LeetCode Question · Jan 2025 · Los Angeles

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

7 upvotes 2,502 views 3 replies

Question Details

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

Full Details

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 {
\tpublic int minCost(int[] arr, int N) {
\t\t// Write your code here
\t}
}

Question2: Collect-maximum-points-from-Tree

About This Question

This is a reported interview question from a d.e. shaw interview for a swe role during the oa round reported in 2025.

It covers the following topics: Arrays, Binary Tree .

Difficulty rating: Hard