Amazon | Phone | 2022
Anonymous User
475

Question 1.

Design a data structure that supports the following operations in Θ(1) time.

add(x)
search(x)
delete(x)
getRandom(x)
deleteMax()
deleteMin()
deleteRandom()

Constraints:
All operations have to be done in constant time only.
-2^31 <= x <= 2^31 - 1
At most 2 * 105 calls will be made to add, delete, and getRandom.
There will be at least one element in the data structure when getRandom is called.
Duplicates allowed.

Question 2.

Given a target value k, find minimum no of steps needed to add to become k with only (1, 2, 3, 4, 5)
 Input k = 14
 Output ans = 3   (5 + 5 + 4)

Please provide solutions with working codes.

Comments (5)