Categories of Questions

## DE Shaw Array Questions

**Question 1. Relative Sort Array Leetcode Solution** In this problem, we are given two arrays of positive integers. All elements of the second array are distinct and are present in the first array. However, the first array can contain duplicate elements or elements that are not in the second array. We need to sort the first array ...

**Question 2. Longest Subarray Having Count of 1s One More than Count of 0s** We have given an array of integers. An array contains 1’s and 0’s only. The problem statement asks to find out the length of the longest Sub-Array which having the quantity of 1’s digit is just one more than the count of 0’s in a sub-array. Example Input: arr[] = ...

**Question 3. Best Time to Buy and Sell Stock II Leetcode Solution** Problem statement In the problem “Best Time to Buy and Sell Stock II,” we are given an array where each element in the array contains the price of the given stock on that day. The definition of the transaction is buying one share of stock and selling that one share ...

**Question 4. Subarray with 0 sum** The problem “Find if there is a subarray with 0 sum” states that you are given an integer array containing negative integers as well. The problem statement asks to determine if any sub-array of size at-least 1. This sub-array should have a sum equal to 1. Example arr[] = {2,1,-3,4,5} ...

**Question 5. Longest Bitonic Subsequence** Suppose you have an array of integers, the problem statement asks to find out the longest bitonic subsequence. The bitonic sequence of an array is considered as the sequence which first increases and then decreases. Example arr[] = {1,4,2,76,43,78,54,32,1,56,23} 7 Explanation 1 ⇒ 4 ⇒ 76 ⇒ 78 ⇒ 54 ...

**Question 6. Array Queries for multiply replacements and product** The problem “Array Queries for multiply, replacements and product” states that you are given an array of integer and there will be three types of queries, where you have to solve the following type of queries: Type 1: There will be three values left, right and a number X.In this ...

**Question 7. Constant time range add operation on an array** You have given an integer array and initially, it was initialized as 0 and also given a range. The task is to add the given number in the range of the array and print the resultant array. Example arr[] = {0, 0, 0, 0, 0} Query: {(0, 2, 50), (3, ...

**Question 8. Queries for counts of array elements with values in given range** Problem Statement The problem “Queries for counts of array elements with values in given range” states that you have an integer array and two number x and y. The problem statement asks to find out the count of numbers present in array that lies between the given x and y. ...

**Question 9. Number of elements less than or equal to a given number in a given subarray** Problem Statement The problem “Number of elements less than or equal to a given number in a given subarray” states that you are given an integer array and q number of queries. There will be two types of queries à queryUpdate(i, v): There will be two integers i and v, ...

**Question 10. GCDs of given index ranges in an array** Problem Statement The problem ‘GCDs of given index ranges in an array” states that you are given an integer array and some range queries. The problem statement asks to find out the Greatest Common Divisor of the sub-array so formed within the range. Example arr[] = {10, 5, 18, 9, ...

**Question 11. Queries for GCD of all numbers of an array except elements in a given range** Problem Statement The “Queries for GCD of all numbers of an array except elements in a given range” problem states that you will be given an integer array and a q number of queries. Each query contains the number left and right. The problem statement asks to find out the ...

**Question 12. Subset with sum divisible by m** Problem Statement The problem “Subset with sum divisible by m” states that you are given an array of non-negative integers and an integer m. Now you need to find if there is a subset having sum divisible by m. That is the sum of the subset should give 0 as ...

**Question 13. Products of ranges in an array** Problem Statement The problem “Products of ranges in an array” states that you are given an integer array consisting of numbers range from 1 to n and q number of queries. Each query contains the range. The problem statement asks to find out the product within the given range under ...

**Question 14. Best Time to Buy and Sell Stock** Problem Statement The problem “Best Time to Buy and Sell Stock” states that you are given an array of prices of length n, where the ith element stores the price of stock on ith day. If we can make only one transaction, that is, to buy on one day and ...

**Question 15. Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space** Problem Statement You are given an array of integers. The problem “Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space” asks to shuffle all the numbers in the array such that the numbers which are like (x0, x1, x2, x3, y0, y1, y2, y3) will be shuffled like x0, y0, ...

**Question 16. Distinct adjacent elements in an array** Problem Statement Suppose we have an integer array. The problem “Distinct adjacent elements in an array” asks to determine if it is possible to get the array in which all the adjacent numbers are distinct or not by swapping up two adjacent or neighbour elements in an array if it ...

**Question 17. Product of array except self** Problem Statement “Product of array except self” problem, states that you are given an array a [ ]. Print another array p [ ] of the same size such that value at i’th index of array p is equal to the product of all the elements of the original array ...

**Question 18. Find pairs with given sum such that elements of pair are in different rows** Problem Statement “Find pairs with given sum such that elements of pair are in different rows” problem states that you are given a matrix of integers and a value called “sum”. The problem statement asks to find out all the pairs in a matrix that sums up to a given ...

**Question 19. Common elements in all rows of a given matrix** Problem Statement “Common elements in all rows of a given matrix” problem state that, you are given a matrix of M*N. The problem statement asks to find out all the common elements in a given matrix in each row of the matrix in O(M*N) time. Example arr[]={{12, 1, 4, 5, ...

**Question 20. Maximum sum bitonic subarray** Problem Statement An array having n integers is given to us. We need to find the maximum sum bitonic subarray. A bitonic subarray is nothing but just a subarray where the elements are arranged in a specific order. Such that the first elements are in increasing order and then in ...

**Question 21. Largest Sum Contiguous Subarray** Problem Statement You are given an array of integers. The problem statement asks to find out the largest sum contiguous subarray. This means nothing but to find a subarray (continuous elements) which has the largest sum among all other subarrays in the given array. Example arr[] = {1, -3, 4, ...

**Question 22. Matrix Chain Multiplication** In the matrix chain multiplication II problem, we have given the dimensions of matrices, find the order of their multiplication such that the number of operations involved in multiplication of all the matrices is minimized. Consider you have 3 matrices A, B, C of sizes a x b, b x ...

**Question 23. Find the Peak Element from an Array** Problem Statement In the “Find the Peak Element from an Array” problem we have given an input array of integers. Find a peak element. In an array, an element is a peak element, if the element is greater than both the neighbours. For corner elements, we can consider the only ...

**Question 24. A Product Array Puzzle** Problem Statement In a product array puzzle problem we need to construct an array where the ith element will be the product of all the elements in the given array except element at the ith position. Example Input 5 10 3 5 6 2 Output 180 600 360 300 900 ...

## DE Shaw String Questions

**Question 25. Maximum weight transformation of a given string** Problem Statement The maximum weight transformation of a given string problem states that given a string consisting only of two characters ‘A’ and ‘B’. We have an operation where we can transform string to another string by toggling any character. Thus many transformations are possible. Out of all the possible ...

**Question 26. Substring With Concatenation Of All Words** In substring with the concatenation of all words problem, we have given a string s and a list consist of many words each of the same length. Print the starting index of the substring which can be the result of the concatenation of all the words in the list in ...

## DE Shaw Tree Questions

**Question 27. Number of elements less than or equal to a given number in a given subarray** Problem Statement The problem “Number of elements less than or equal to a given number in a given subarray” states that you are given an integer array and q number of queries. There will be two types of queries à queryUpdate(i, v): There will be two integers i and v, ...

**Question 28. GCDs of given index ranges in an array** Problem Statement The problem ‘GCDs of given index ranges in an array” states that you are given an integer array and some range queries. The problem statement asks to find out the Greatest Common Divisor of the sub-array so formed within the range. Example arr[] = {10, 5, 18, 9, ...

## DE Shaw Stack Questions

**Question 29. Queue using Stacks** In queue using a stack problem, we have to implement the following functions of a queue using the standard functions of stack data structure, Enqueue: Add an element to the end of the queue Dequeue: Remove an element from the start of the queue Example Input: Enqueue(5) Enqueue(11) Enqueue(39) Dequeue() ...

## DE Shaw Queue Questions

**Question 30. Implementation of Deque using Doubly Linked List** Problem Statement The problem “Implementation of Deque using Doubly Linked List” states that you need to implement the following functions of Deque or Doubly Ended Queue using a doubly linked list, insertFront(x) : Add element x at the starting of Deque insertEnd(x) : Add element x at the end of ...

**Question 31. Queue using Stacks** In queue using a stack problem, we have to implement the following functions of a queue using the standard functions of stack data structure, Enqueue: Add an element to the end of the queue Dequeue: Remove an element from the start of the queue Example Input: Enqueue(5) Enqueue(11) Enqueue(39) Dequeue() ...

## DE Shaw Matrix Questions

**Question 32. Find pairs with given sum such that elements of pair are in different rows** Problem Statement “Find pairs with given sum such that elements of pair are in different rows” problem states that you are given a matrix of integers and a value called “sum”. The problem statement asks to find out all the pairs in a matrix that sums up to a given ...

**Question 33. Common elements in all rows of a given matrix** Problem Statement “Common elements in all rows of a given matrix” problem state that, you are given a matrix of M*N. The problem statement asks to find out all the common elements in a given matrix in each row of the matrix in O(M*N) time. Example arr[]={{12, 1, 4, 5, ...

**Question 34. Matrix Chain Multiplication** In the matrix chain multiplication II problem, we have given the dimensions of matrices, find the order of their multiplication such that the number of operations involved in multiplication of all the matrices is minimized. Consider you have 3 matrices A, B, C of sizes a x b, b x ...

## DE Shaw Other Questions

**Question 35. Maximum sum of a path in a Right Number Triangle** The problem “Maximum sum of a path in a Right Number Triangle” states that you are given some integers in the form of a right number triangle. Find out the maximum sum you can achieve if you start from the top and move towards the base such that you move ...

**Question 36. Write a function to get the intersection point of two Linked Lists** Problem Statement The problem “Write a function to get the intersection point of two Linked Lists” states that you are given two linked lists. But they are not independent linked lists. They are connected at some point. Now you need to find this point of intersection of these two lists. ...

**Question 37. 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. ...