DE Shaw | Online Assessment | Min cost to remove all elements of the array | Jan 2025
Round 1
Questions: Question 1: Calculate the minimum cost to remove all the elements from an array. In every operation you can remove any two elements from the first three elements of the array, the cost to remove them would be maximum of the removed ones. Also, the third unremoved element would become the first element for the next array. When the array size would become less than 3, remove all of them with a cost as maximum of them.
Example:
arr = [1, 2, 3, 4, 5]
Suppose you removed 2 and 3 (comes in first 3 elements):
cost = Max(2, 3) = 3;
For the next operation, our array would become [1, 4, 5]
. Suppose you chose to remove 4 and 5:
cost += 5 => cost = 8;
Now our array is [1]. Remove it with cost 1:
cost = 8 + 1 = 9
Constraints:
- n = arr.length
- 1 <= n <= 10^4
- 1 <= arr[i] <= 10^5
class Solution { public int minCost(int[] arr, int N) { // Write your code here } }
Question 2: Collect-maximum-points-from-Tree
Candidate's Approach
No approach provided.
Interviewer's Feedback
No feedback provided.