LinkedIn | SSE | 6 YOE | India

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-11-22Added By Anonymous
Source: Link

Tech Screening ------------------------------

•Questions on process vs threads, virtual memory, etc
•Design a data structure that can perform the following:
11. add an element 22. remove a random element

Optimal 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:

•Question based on connected components of a graph
•Celebrity problem [GFG]

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:

•Given a BST of Integer numbers and a target, find the k closest points to it. (target may not be present in the BST and closest means absolute distance) - need to do this in O(n) TC and O(k) SC
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,7
•Design a datastructure which can store keys, give the key with max frequency and min frequency. The keys can be incremented or decremented by 1 (this is the hint)
1/* 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 -> 4

I 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.



Comments