Recently, I gave online assessment for Apple for Software Engineer position over Hackerrank. There were total 2 coding questions and were given 50 min to complete.
Problem 1: Save the Plants
There are n number of dying plants. Each plant i has a saving factor sf[i], which is the minimum size of fertilizer bag that the plant can be saved with, and each fertilizer bag j has a size s[j]. If s[j] >= sf[i], we want to assign the fertilizer bag j to plant i, and the plant can be saved. Maximize the number of plants that we can save.
Example 1:
Input: saving factor (sf) = [1,2,3], fertilizer bag size (s) = [1,1]
Output: 1
Explanation: You have 3 plants and 2 fertilizer bags.
The saving factor of 3 plants are 1, 2, 3.
And even though you have 2 fertilizer bag, since their size is both 1, you could only save the plant having saving factor 1
You need to output 1.
Problem 2: Teacher and Gift box
You are teacher and wanted to give some gift to N students. You ordered N gift box from amazon and each gift box have some gift items inside it. But each gift box has different number of gift items inside it.
You as teacher wanted to make sure, each gift box should contains approximately same number of gifts items. And wanted to minimised the difference of gift items in any two gift box.
You have pool of infinite number of gift items with you, which you can used that pool to balance (add/subtract) gift items in any gift box but with only given two operation.
For example if you have N = 4 students and array of gift box represented as gift_boxes = [1,4,3,8], each giftboxes[i] represent number of gift items inside that gift box.
If you want, you can perform below two operation on any gift box, any number of time.
Now, "array-diff" of giftboxes array is maximum difference between number of gift items of any two gift box in the gift_boxes array.
Return the minimum "array-diff" of gift_boxes array can have after performing some number of above operations.
Example 1:
Input: gift_boxes = [1,4,3,8]
Output: 1
Explanation: You can transtorm the array to
[1,4,3,8] -> "array-diff" of gift_boxes array = 8-1 = 7
[2,4,3,8] -> "array-diff" of gift _boxes array = 8-2 = 6
[2,2,3,8] - "array-diff" of gift_boxes array = 8-2 = 6
[2,2,3,4] -> "array-diff" of gift_boxes array = 4-2 = 2
[2,2,3,2] - "array-diff" of gift_boxes array = 3-2 = 1
then minimum "array-diff" of gift _boxes array will be = 1.