Linkedin Telephonic

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2021-02-10Added By Anonymous
Source: Link

YOE: 6 years


Location: Bay area

Intro

Random/standard Operating System questions: What is page fault, critical section, give real life example for locks. What happens in case of a page fault. Standard silberschatz operating systems level questions. Just wanted to hear terms like semaphores, locks, mutex. Just the terms. They didn't ask what is the difference.

1.) Find if the tree is mirror of another other. I myself asked if tree is binary? So, the interviewer later extended the problem to n-arry tree. Time, Space complexity. The shadow interviewer wanted to understand why did I say that

recursion will take memory (as I had not used tail end optimization) but otherwise memory is O(1) from user perspective. I explained a bit about instruction pointers and how compilers keep traack where do they want to go next.


2.)

1""" 2The problem was something like say you have a list 3 [1, [2, 3], 4, [5, 6, [7]]] 4 You have to return the sum such that each sum at each level is multiplied by depth in reverse. 5 For instance 1, 4 is at level 1 but total depth of the arr = 3 so 1+4 will be multiplies by 3. 6 [2, 3, 5, 6] is at level 2 but it will be multiplies by 2 7 [7] is at level 3 but it will be multiplied by 1. 8 9 10[1, 2, 3, 4] - Are all at same level. 11[1, [2], 3] - 1, 3 are at same level. 12""" 13 14 15 16def mainFunction(arr): 17 sum_of_levels = {} 18 saveLevels(arr, 0, sum_of_levels) 19 print(sum_of_levels) 20 rev_depth = len(sum_of_levels.keys()) 21 22 result = 0 23 for k, v in sum_of_levels.items(): 24 result += v * rev_depth 25 rev_depth -= 1 26 27 return result 28 29def saveLevels(arr, d, sum_of_levels): 30 31 32 total = 0 33 for item in arr: 34 if isinstance(item, list): 35 saveLevels(item, d + 1, sum_of_levels) 36 else: 37 total += item 38 39 sum_of_levels[d] = sum_of_levels.get(d, 0) + total 40 41print(mainFunction([1, 2, 3, 4])) 42print(mainFunction([1, 2, [3, 4]])) 43print(mainFunction([1, 2, [3, [4] ] ])) 44print(mainFunction([1, 2, [3], [4] ])) 45print(mainFunction([1, [2, 3], 4, [5, 6, [7]]]))

Verdict: Reject.

Comments