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.)
"""
The problem was something like say you have a list
[1, [2, 3], 4, [5, 6, [7]]]
You have to return the sum such that each sum at each level is multiplied by depth in reverse.
For instance 1, 4 is at level 1 but total depth of the arr = 3 so 1+4 will be multiplies by 3.
[2, 3, 5, 6] is at level 2 but it will be multiplies by 2
[7] is at level 3 but it will be multiplied by 1.
[1, 2, 3, 4] - Are all at same level.
[1, [2], 3] - 1, 3 are at same level.
"""
def mainFunction(arr):
sum_of_levels = {}
saveLevels(arr, 0, sum_of_levels)
print(sum_of_levels)
rev_depth = len(sum_of_levels.keys())
result = 0
for k, v in sum_of_levels.items():
result += v * rev_depth
rev_depth -= 1
return result
def saveLevels(arr, d, sum_of_levels):
total = 0
for item in arr:
if isinstance(item, list):
saveLevels(item, d + 1, sum_of_levels)
else:
total += item
sum_of_levels[d] = sum_of_levels.get(d, 0) + total
print(mainFunction([1, 2, 3, 4]))
print(mainFunction([1, 2, [3, 4]]))
print(mainFunction([1, 2, [3, [4] ] ]))
print(mainFunction([1, 2, [3], [4] ]))
print(mainFunction([1, [2, 3], 4, [5, 6, [7]]]))Verdict: Reject.