DE Shaw | Online Assessment | Min cost to remove all elements of the array | Jan 2025
Anonymous User
2352

I was being contacted by a recruiter through Naukri.com. There were two questions with time limit of 90minutes.
Question level: Mid-Hard.

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 maimum 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.

eg: arr = [1, 2, 3, 4, 5]
suppose you removed 2 and 3 (comes in first 3 elements)
cost = Max(2, 3) = 3;

for 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

Constaraints:
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
	}
}

Question2: Collect-maximum-points-from-Tree

Comments (3)