LinkedIn | SSE | 6 YOE | India
Tech Screening ------------------------------
11. add an element
22. remove a random elementOptimal solution needs to be done in O(1) for all operations - can be done with ArrayList implementation and swapping a random generated index element with the last element and decrementing list size.
Loop ----------------------------------------
Coding Module 1:
I was able to the first one, but the second one optimal solution was expected i could only do the brute force in O(n^2) TC
Coding Module 2:
1// Given the following Binary Search Tree:
2
3// 10
4// / \
5// 5 20
6// /\ /\
7// 1 6 19 35
8// \
9// 7
10
11// Given target=8, and k=3, it should return 6,7,10
12// Given target=6, and k=3, it should return 5,6,71/*
2 * Implement the following interface.
3 *
4 * All methods must run in O(1) time.
5 */
6
7interface AllForOne {
8 /**
9 * Increment the provided key's frequency value by 1. Or add the key with the frequency 1 if it's not present.
10 *
11 * Note that the actual frequency value of the key is not necessary to expose to the caller; its value is only kept internally for bookkeeping purposes.
12 */
13 void incrementKey(String key);
14
15 /**
16 * Decrement the provided key's frequency value by 1. Or remove the key if its frequency is 1. Do nothing if the key is not present.
17 *
18 * Note that the actual frequency value of the key is not necessary to expose to the caller; its value is only kept internally for bookkeeping purposes.
19 */
20 void decrementKey(String key);
21
22 /**
23 * Get one of the keys with the max frequency, or empty string if there are no keys.
24 */
25 String getMaxKey();
26
27 /**
28 * Get one of the keys with the min frequency, or empty string if there are no keys.
29 */
30 String getMinKey();
31}
32
33incrementKey("foo"); // void
34incrementKey("foo"); // void
35incrementKey("foo"); // void
36incrementKey("foo"); // void
37incrementKey("bar"); // void
38incrementKey("bar"); // void
39incrementKey("bar"); // void
40incrementKey("bar"); // void
41getMaxKey(); // "foo" or "bar" can be returned because foo -> 4, and bar -> 4
42getMinKey(); // "foo" or "bar" can be returned because foo -> 4, and bar -> 4
43decrementKey("foo"); // void
44getMaxKey(); // "bar" because foo -> 3, and bar -> 4
45getMinKey(); // "foo" because foo -> 3, and bar -> 4
46decrementKey("foo"); // void
47decrementKey("foo"); // void
48decrementKey("foo"); // void
49getMaxKey(); // "bar" because foo is not in the structure, and bar -> 4
50getMinKey(); // "bar" because foo is not in the structure, and bar -> 4I couldn't do the first one(it might work with in order traversal + a k size Deque/ doubly linkedList), second one i gave a valid solution approach using the concepts from LRU cache problem.
Complex System Design:
Design a Metric Collection System - focus on the data store.
Host Manager:
General discussion of projects and deep dive into a recent project, your role and impact, challenges.