Round 1: Technical Interview
Maximum of Minimums of Every Window
Given an array A of size n and an integer x, implement the following steps:
- Consider every contiguous subarray of length
x, or sliding window. - Find the minimum value in each window.
- Return the maximum of all those minimum values.
For example, A = [1, 3, -1, 5, 3, 6] and x = 3:
[1, 3, -1] -> minimum is -1
[3, -1, 5] -> minimum is -1
[-1, 5, 3] -> minimum is -1
[5, 3, 6] -> minimum is 3
The final return value is 3.
The main point of the question is to use a sliding window and a monotonic deque to maintain the current window's minimum efficiently and avoid repeated computation.
SQL — Classify Nodes in a Tree
Given a Tree table containing id (node ID) and pid (parent node ID), write a SQL query that classifies each node as follows:
- Root: has no parent, so
pidisNULL. - Inner: has at least one child and also has a parent.
- Leaf: has no children and has a parent.
Example input:
id pid
1 NULL
2 1
3 1
4 2
Expected output:
1 -> Root
2 -> Inner
3 -> Leaf
4 -> Leaf
Discussion
Loading comments…