Skip to main content

Command Palette

Search for a command to run...

Top 10 DE Shaw Coding Interview Questions from 2025

Updated
8 min read

Introduction

In this blog post, we'll share the most commonly asked coding interview questions at DE Shaw. If you don't have months to study for your interviews, you can use AI tools like Chatmagic to generate solutions quickly and efficiently - helping you pass the interviews and get the job offer!

Problem #1: Find Minimum Cost to Remove Array Elements

You are given an integer array nums. Your task is to remove all elements from the array by performing one of the following operations at each step until nums is empty: Choose any two elements from the first three elements of nums and remove them. The cost of this operation is the maximum of the two elements removed. If fewer than three elements remain in nums, remove all the remaining elements in a single operation. The cost of this operation is the maximum of the remaining elements. Return the minimum cost required to remove all the elements. Example 1: Input: nums = [6,2,8,4] Output: 12 Explanation: Initially, nums = [6, 2, 8, 4]. In the first operation, remove nums[0] = 6 and nums[2] = 8 with a cost of max(6, 8) = 8. Now, nums = [2, 4]. In the second operation, remove the remaining elements with a cost of max(2, 4) = 4. The cost to remove all elements is 8 + 4 = 12. This is the minimum cost to remove all elements in nums. Hence, the output is 12. Example 2: Input: nums = [2,1,3,3] Output: 5 Explanation: Initially, nums = [2, 1, 3, 3]. In the first operation, remove nums[0] = 2 and nums[1] = 1 with a cost of max(2, 1) = 2. Now, nums = [3, 3]. In the second operation remove the remaining elements with a cost of max(3, 3) = 3. The cost to remove all elements is 2 + 3 = 5. This is the minimum cost to remove all elements in nums. Hence, the output is 5. Constraints: 1 <= nums.length <= 1000 1 <= nums[i] <= 106

Topics: Array, Dynamic Programming

Problem #2: Maximum Points Tourist Can Earn

You are given two integers, n and k, along with two 2D integer arrays, stayScore and travelScore. A tourist is visiting a country with n cities, where each city is directly connected to every other city. The tourist's journey consists of exactly k 0-indexed days, and they can choose any city as their starting point. Each day, the tourist has two choices: Stay in the current city: If the tourist stays in their current city curr during day i, they will earn stayScore[i][curr] points. Move to another city: If the tourist moves from their current city curr to city dest, they will earn travelScore[curr][dest] points. Return the maximum possible points the tourist can earn. Example 1: Input: n = 2, k = 1, stayScore = [[2,3]], travelScore = [[0,2],[1,0]] Output: 3 Explanation: The tourist earns the maximum number of points by starting in city 1 and staying in that city. Example 2: Input: n = 3, k = 2, stayScore = [[3,4,2],[2,1,2]], travelScore = [[0,2,1],[2,0,4],[3,2,0]] Output: 8 Explanation: The tourist earns the maximum number of points by starting in city 1, staying in that city on day 0, and traveling to city 2 on day 1. Constraints: 1 <= n <= 200 1 <= k <= 200 n == travelScore.length == travelScore[i].length == stayScore[i].length k == stayScore.length 1 <= stayScore[i][j] <= 100 0 <= travelScore[i][j] <= 100 travelScore[i][i] == 0

Topics: Array, Dynamic Programming, Matrix

Problem #3: Binary Tree Cameras

You are given the root of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children. Return the minimum number of cameras needed to monitor all nodes of the tree. Example 1: Input: root = [0,0,null,0,0] Output: 1 Explanation: One camera is enough to monitor all nodes if placed as shown. Example 2: Input: root = [0,0,null,0,null,0,null,null,0] Output: 2 Explanation: At least two cameras are needed to monitor all nodes of the tree. The above image shows one of the valid configurations of camera placement. Constraints: The number of nodes in the tree is in the range [1, 1000]. Node.val == 0

Topics: Dynamic Programming, Tree, Depth-First Search, Binary Tree

Problem #6: Shortest Subarray to be Removed to Make Array Sorted

Given an integer array arr, remove a subarray (can be empty) from arr such that the remaining elements in arr are non-decreasing. Return the length of the shortest subarray to remove. A subarray is a contiguous subsequence of the array. Example 1: Input: arr = [1,2,3,10,4,2,3,5] Output: 3 Explanation: The shortest subarray we can remove is [10,4,2] of length 3. The remaining elements after that will be [1,2,3,3,5] which are sorted. Another correct solution is to remove the subarray [3,10,4]. Example 2: Input: arr = [5,4,3,2,1] Output: 4 Explanation: Since the array is strictly decreasing, we can only keep a single element. Therefore we need to remove a subarray of length 4, either [5,4,3,2] or [4,3,2,1]. Example 3: Input: arr = [1,2,3] Output: 0 Explanation: The array is already non-decreasing. We do not need to remove any elements. Constraints: 1 <= arr.length <= 105 0 <= arr[i] <= 109

Topics: Array, Two Pointers, Binary Search, Stack, Monotonic Stack

Problem #7: Consecutive Numbers Sum

Given an integer n, return the number of ways you can write n as the sum of consecutive positive integers. Example 1: Input: n = 5 Output: 2 Explanation: 5 = 2 + 3 Example 2: Input: n = 9 Output: 3 Explanation: 9 = 4 + 5 = 2 + 3 + 4 Example 3: Input: n = 15 Output: 4 Explanation: 15 = 8 + 7 = 4 + 5 + 6 = 1 + 2 + 3 + 4 + 5 Constraints: 1 <= n <= 109

Topics: Math, Enumeration

Problem #8: Count the Number of Incremovable Subarrays II

You are given a 0-indexed array of positive integers nums. A subarray of nums is called incremovable if nums becomes strictly increasing on removing the subarray. For example, the subarray [3, 4] is an incremovable subarray of [5, 3, 4, 6, 7] because removing this subarray changes the array [5, 3, 4, 6, 7] to [5, 6, 7] which is strictly increasing. Return the total number of incremovable subarrays of nums. Note that an empty array is considered strictly increasing. A subarray is a contiguous non-empty sequence of elements within an array. Example 1: Input: nums = [1,2,3,4] Output: 10 Explanation: The 10 incremovable subarrays are: [1], [2], [3], [4], [1,2], [2,3], [3,4], [1,2,3], [2,3,4], and [1,2,3,4], because on removing any one of these subarrays nums becomes strictly increasing. Note that you cannot select an empty subarray. Example 2: Input: nums = [6,5,7,8] Output: 7 Explanation: The 7 incremovable subarrays are: [5], [6], [5,7], [6,5], [5,7,8], [6,5,7] and [6,5,7,8]. It can be shown that there are only 7 incremovable subarrays in nums. Example 3: Input: nums = [8,7,6,6] Output: 3 Explanation: The 3 incremovable subarrays are: [8,7,6], [7,6,6], and [8,7,6,6]. Note that [8,7] is not an incremovable subarray because after removing [8,7] nums becomes [6,6], which is sorted in ascending order but not strictly increasing. Constraints: 1 <= nums.length <= 105 1 <= nums[i] <= 109

Topics: Array, Two Pointers, Binary Search

Problem #9: Minimum Number of Taps to Open to Water a Garden

There is a one-dimensional garden on the x-axis. The garden starts at the point 0 and ends at the point n. (i.e., the length of the garden is n). There are n + 1 taps located at points [0, 1, ..., n] in the garden. Given an integer n and an integer array ranges of length n + 1 where ranges[i] (0-indexed) means the i-th tap can water the area [i - ranges[i], i + ranges[i]] if it was open. Return the minimum number of taps that should be open to water the whole garden, If the garden cannot be watered return -1. Example 1: Input: n = 5, ranges = [3,4,1,1,0,0] Output: 1 Explanation: The tap at point 0 can cover the interval [-3,3] The tap at point 1 can cover the interval [-3,5] The tap at point 2 can cover the interval [1,3] The tap at point 3 can cover the interval [2,4] The tap at point 4 can cover the interval [4,4] The tap at point 5 can cover the interval [5,5] Opening Only the second tap will water the whole garden [0,5] Example 2: Input: n = 3, ranges = [0,0,0,0] Output: -1 Explanation: Even if you activate all the four taps you cannot water the whole garden. Constraints: 1 <= n <= 104 ranges.length == n + 1 0 <= ranges[i] <= 100

Topics: Array, Dynamic Programming, Greedy

Problem #10: Flatten Nested List Iterator

You are given a nested list of integers nestedList. Each element is either an integer or a list whose elements may also be integers or other lists. Implement an iterator to flatten it. Implement the NestedIterator class: NestedIterator(List nestedList) Initializes the iterator with the nested list nestedList. int next() Returns the next integer in the nested list. boolean hasNext() Returns true if there are still some integers in the nested list and false otherwise. Your code will be tested with the following pseudocode: initialize iterator with nestedList res = [] while iterator.hasNext() append iterator.next() to the end of res return res If res matches the expected flattened list, then your code will be judged as correct. Example 1: Input: nestedList = [[1,1],2,[1,1]] Output: [1,1,2,1,1] Explanation: By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,1,2,1,1]. Example 2: Input: nestedList = [1,[4,[6]]] Output: [1,4,6] Explanation: By calling next repeatedly until hasNext returns false, the order of elements returned by next should be: [1,4,6]. Constraints: 1 <= nestedList.length <= 500 The values of the integers in the nested list is in the range [-106, 106].

Topics: Stack, Tree, Depth-First Search, Design, Queue, Iterator

More from this blog

C

Chatmagic blog

2894 posts