Categories of Questions

## Array Questions Delhivery

**Question 1. Maximum Distance Between two Occurrences of Same Element in Array** Suppose you are given an array with some repeated numbers. We have to find the maximum distance between the two same occurrences of a number with different index, present in an array. Example Input: array = [1, 2, 3, 6, 2, 7] Output: 3 Explanation: Because elements at array [1] ...

**Question 2. Group Multiple Occurrence of Array Elements Ordered by first Occurrence** You are given a question in which you have given an unsorted array with multiple occurrences of numbers. The task is to group all the multiple occurrences of array elements ordered by first occurrence. Meanwhile, the order should be the same as the number comes. Example Input: [ 2, 3,4,3,1,3,2,4] ...

**Question 3. Maximum Array from Two given Arrays Keeping Order Same** Suppose we have two integers array of same size n. Both of the arrays can contain common numbers as well. The problem statement asks to form the resultant array that contains the ‘n’ maximum values from both of the arrays. The first array should be prioritized (elements of the first ...

**Question 4. Find Largest d in Array such that a + b + c = d** Problem Statement Suppose you have an array of integers. Input values are all distinct elements. The problem “Find largest d in array such that a + b + c = d” asks to find out the largest element ‘d’ in the set such that a + b + c = ...

**Question 5. Maximum sum of pairs with specific difference** The problem “Maximum sum of pairs with specific difference” states that you are given an array of integers and an integer K. Then we are asked to find out the maximum sum of independent pairs. We can pair two integers if they have an absolute difference of less than K. ...

**Question 6. Maximum subsequence sum such that no three are consecutive** The problem “Maximum subsequence sum such that no three are consecutive ” states that you are given an array of integers. Now you need to find a subsequence that has the maximum sum given that you cannot consider three consecutive elements. To recall, a subsequence is nothing but an array ...

**Question 7. Longest subarray not having more than K distinct elements** The problem “Longest subarray not having more than K distinct elements” states that suppose you have an array of integers, the problem statement asks to find out the longest sub-array that having not greater than k different elements. Example arr[] = {4, 3, 5, 2, 1, 2, 0, 4, 5} ...

**Question 8. Find subarray with given sum (Handles Negative Numbers)** The problem “Find subarray with given sum (Handles Negative Numbers)” states that you are given an integer array, containing negative integers as well and a number called “sum”. The problem statement asks to print the sub-array, which sums up to a given number called “sum”. If more than one sub-array ...

**Question 9. Find elements which are present in first array and not in second** The problem “Find elements which are present in first array and not in second” states that you are given two arrays. Arrays consist of all the integers. You have to find out the numbers which will not be present in the second array but present in the first array. Example ...

**Question 10. Bubble sort using two Stacks** Problem Statement The problem “Bubble sort using two Stacks” states that you are given an array a[ ] of size n. Create a function to sort the given array a[ ] using a bubble sort paradigm with two stack data structures. Example a[ ] = {15, 12, 44, 2, 5, ...

**Question 11. Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’** Problem Statement The problem ” Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’ ” states that you have an “n” sized array containing integers. The numbers in the array are in a range of 0 to n-1. The problem statement asks to rearrange the array in ...

**Question 12. Find the minimum distance between two numbers** Problem Statement You have given an array and two numbers called x and y. The problem “Find the minimum distance between two numbers” asks to find out the minimum possible distance between them. The array given can have common elements. You can assume that both x and y are different. ...

**Question 13. Find the Only Repetitive Element Between 1 to N-1** In finding the only repetitive element between 1 to N-1 problem we have given an array of random integers within a range from 1 to n-1. There will be one number that is repeated. Your task is to find that number. Example Input [2,3,4,5,2,1]A Output 2 Explanation 2 is the ...

**Question 14. Change the Array into Permutation of Numbers From 1 to N** In this problem, we have given an array A of n elements. We need to change the array into a permutation of numbers from 1 to n using minimum replacements in the array. Example Input: 2 2 3 3 Output: 2 1 3 4 Input : 3 2 1 7 ...

## String Questions Delhivery

**Question 15. Shortest Palindrome** In the shortest palindrome problem, we have given a string s of length l. Add characters in front of it to make it palindrome if it’s not. Print the smallest count of characters used to make the given string a palindrome. Example Input : s = abc Output: 2 (by ...

**Question 16. Reverse a String using Stack** We have given a string s of length n which contains lower case letters, upper case letters, integers, and some special symbol. Reverse the given string using stack. Let’s see some examples for better understanding. Example Input s = “TutorialCup” Output puClairotuT Input s = “Stack” Output kcatS Using Stack ...

**Question 17. Check if String can Become Empty by Recursively Deleting given Substring** Problem Statement In the “Check if string can become empty by recursively deleting given substring” problem we have given two strings “s” and “t”. We have to check if the given input string “s” can be deleted completely by deleting the given input sub-string “t” recursively. Note: Given sub-string should ...

**Question 18. Compare Two Version Numbers** Problem Statement Given two input strings, which are in form of version numbers. A version number looks like a.b.c.d where a, b, c, d are integers. Therefore, the version number is a string in which numbers are separated by dots. We need to compare the two strings (version numbers) and ...

**Question 19. Longest Palindrome can be Formed by Removing or Rearranging Characters** Problem Statement In the “Longest Palindrome can be Formed by Removing or Rearranging Characters” problem we have given a string “s”. Find the longest palindrome that can be constructed by removing or rearranging some characters or possibly zero characters from the string. There may be multiple solutions possible, you can ...

## Tree Questions Delhivery

**Question 20. Types of Binary Tree** Before we proceed, we first know what BT really is? Binary Tree is a type of data structure that is hierarchical in nature. A BT is represented by nodes where every node has left, a right pointer, and data as the weight of node. Each node can contain a maximum ...

**Question 21. Insertion in a Binary Tree** In this article, we will learn the insertion in a binary tree. We have already seen the concept of BFS in the previous article, so here we will use the same concept to insert the data in a binary tree. The concept is traversing the tree in level order and ...

## Graph Questions Delhivery

**Question 22. Graph and its representation** A graph is an abstract data type representing relations or connections between objects(like cities are connected by rough road). In the graph and its representation, basically, the relation is denoted by edges and objects by vertices(nodes). A graph consists of a finite set of vertices and edges. A graph is ...

## Stack Questions Delhivery

**Question 23. Check if stack elements are pairwise consecutive** Problem Statement “Check if stack elements are pairwise consecutive” problem states that you are given a stack data structure of integer type. Create a function to check if all the given elements are pairwise consecutive ( either in increasing or decreasing order ) or not. If the number of elements ...

**Question 24. Reversing a Queue** In Reversing a Queue problem we have given a queue, write an algorithm to reverse the queue. Examples Input queue = 10 -> 8 -> 4 -> 23 Output queue = 23->4->8->10 Input queue = 11 -> 98 -> 31 -> 42 -> 73 -> 6 Output queue = 6 ...

**Question 25. The Stock Span Problem** This problem “The Stock Span Problem” comes under the financial aspect. In this problem, we find the stock span for the stock price of each day. The maximum number of consecutive days just before any particular day for which the price of the stock of the days before it is ...

**Question 26. Reverse a String using Stack** We have given a string s of length n which contains lower case letters, upper case letters, integers, and some special symbol. Reverse the given string using stack. Let’s see some examples for better understanding. Example Input s = “TutorialCup” Output puClairotuT Input s = “Stack” Output kcatS Using Stack ...

## Queue Questions Delhivery

**Question 27. Reversing a Queue** In Reversing a Queue problem we have given a queue, write an algorithm to reverse the queue. Examples Input queue = 10 -> 8 -> 4 -> 23 Output queue = 23->4->8->10 Input queue = 11 -> 98 -> 31 -> 42 -> 73 -> 6 Output queue = 6 ...

**Question 28. Insertion in a Binary Tree** In this article, we will learn the insertion in a binary tree. We have already seen the concept of BFS in the previous article, so here we will use the same concept to insert the data in a binary tree. The concept is traversing the tree in level order and ...

## Other Questions Delhivery

**Question 29. Find missing elements of a range** The problem Find missing elements of a range” states that you are given an array of distinct elements within a particular range and a range given as low and high. Find all the missing elements within a range which is not present in an array. The output should be in ...

**Question 30. Print Fibonacci sequence using 2 variables** Problem Statement The problem “Print Fibonacci sequence using 2 variables” states that you need to print the Fibonacci sequence but there is a limitation of using only 2 variables. Example n = 5 0 1 1 2 3 5 Explanation The output sequence has the first five elements of the ...

**Question 31. Tiling Problem** Problem Statement The “Tiling Problem” states that you have a grid of size 2 x N and a tile of size 2 x 1. So, find the number of ways to tile the given grid. Example 3 2 Explanation: Approach for Tiling Problem We can solve this problem by using recursion. ...

**Question 32. OSI Model** This model was developed in 1983 by the International Standards Organization (ISO). This was the first step taken to standardized the international protocols used in various layers. As it deals with connecting open systems, that is, systems that are open for communication with other systems, the model is called the ...

**Question 33. Ugly Numbers** The positive numbers whose only prime factors are 2, 3, or 5 are known as ugly numbers. For eg- 8 is an ugly number because it’s an only prime factor is 2 but 7 is not an ugly number because it’s a prime factor is 7. 1 being an exception ...