Solve 4 LeetCode algorithm problems
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This set evaluates algorithmic problem-solving and mastery of core data structures and algorithms, covering function execution tracking, interval overlap and resource allocation, vertical-order tree traversal, and selection for kth-order statistics.
Constraints
- 1 <= n <= 10^4
- 1 <= len(logs) <= 10^5
- 0 <= function_id < n
- 0 <= timestamp <= 10^9
- logs are in chronological order
- each start has a corresponding end; calls are properly nested
- single-threaded execution; at most one function runs at any time
Hints
- Use a stack to track the active function ids.
- Keep a variable prev to mark the start of the current uninterrupted interval.
- On a start at time t, add t - prev to the current top function before pushing the new one, then set prev = t.
- On an end at time t, pop and add t - prev + 1 to that function, then set prev = t + 1.