InMobi Interview Question

Implement stack with max,push and pop Given unsorted array, find pair with a given sum , O(n) Complexity Puzzle - 7g gold to be distributed in 7 days with min cuts. Asked to Generalize 100 bottles , 1 poisonous. How to determine in O(1)

Interview Answers

Anonymous

May 20, 2017

7g gold to be distributed in 7 days with min cuts: you need to make minum two curt : 1gm and 2gm last will automatically calculate to 4 gm. 1 day - GIve 1gm, you will have 2gm and 4gm in ur hand. 2- day Give 2gm and take 1 gm back, you will have 1gm and 4gm in ur hand. 3- day- give 1 gm , you will have 4gm in ur hand. 4-day - give 4gm, and take back 1 and 2 gm, you will have 2gm and 1gm in ur hand. 5 day - give 1gm, you will have 2gm in ur hand. 6-day - give 2gm and take back 1 gm 7-day give last 1gm Enjoy!!

1

Anonymous

Jan 30, 2017

Use extra stack, always push max , S(1), O(n) - max() returns max element in O(!) complexity Iterate array, see if complement is traversed Many suitable answers to puzzle for 100 bottles, Hint is - Think from their Binary imeplementation

1