DE Shaw | OA | India
Anonymous User
3317

Question 1:
Don't remember the question but can be solved simply using greedy approach. (Sort the array using a custom comparator)

Question 2:
Given an array of different piles of candies, make all the piles equal by either removing one candy from a pile or adding one candy to a pile. The minimum no of candies in a pile should be at least one. At a time, you can add only one candy to a pile or remove one candy from a pile. The cost of adding a candy to a pile c1, and removing a candy from a pile c2 will be given. Find the minimum cost to make all the piles of the same size?
Example:
Arr = 1 2 3 4
C1 = 2
C2 = 1
Output: 5 [ final array: {2,2,2,2} ]
Explanation: add 1 candy to i=0, remove 1 candy form i=2, and remove 2 candies form i=3

Comments (11)