Solve graph path, interval deletion, and robbery
DatabricksSoftware Engineer · HR ScreenLast updated
This interview question evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer for Solve graph path, interval deletion, and robbery states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
Part A — Optimal path with transport modes: You are given a directed weighted graph of a city. Each edge has a travel time and a transport mode label (e.g., walk, bus, subway, bike). Given a source s, destination t, and a set of allowed modes, compute the minimum-time path that only uses edges whose mode is in the allowed set. Describe your algorithm and analyze time/space complexity. Follow-up: if all modes are allowed (no restriction), what algorithm would you choose and why? How do your complexity and implementation details change?
Part B — Maximize non-adjacent loot on a circle: Given n non-negative integers where nums[i] is the cash in the i-th house arranged in a circle, compute the maximum cash you can steal if you cannot rob two adjacent houses and the first and last houses are adjacent and cannot both be robbed. Explain your approach and its complexity.
Part C — Delete an interval, incl. streaming: You are given a sorted list of non-overlapping half-open intervals [start, end). Implement a function deleteInterval(intervals, del) that removes del from intervals (possibly splitting intervals) and returns the remaining intervals. Follow-up: how would you process a high-throughput stream of delete intervals online? What data structures would you use to keep operations efficient and memory-bounded? Analyze complexities.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.