LinkedIn software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
n servers labeled 1 to n. Each connection is a bidirectional link with a bandwidth cost. A network engineer needs...Input: Graph (nodes and edges)MaxStack() — Construct an empty stack.push(value: int) -> None — Push an entry onto the top.pop() -> int — Remove and return the top entry.top() -> int — Return the top entry without removing it.peekMax() -> int — Return the largest value without removing an entry.popMax() -> int — Remove and return the largest value, breaking ties in favor of the entry closest to the top.{"operations":["MaxStack","push","push","push","top","popMax","top","peekMax","pop","top"],"arguments":[[],[5],[1],[5],[],[],[],[],[],[]]}Output:[null,null,null,null,5,5,1,5,1,5]Explanation: After the three pushes, the stack is
[5, 1, 5] from bottom to top. popMax() removes the topmost 5, leaving [5, 1]. The maximum is still 5, while the top is 1. Popping 1 leaves [5].Example 2:Input:{"operations":["MaxStack","push","push","push","popMax","top","peekMax","popMax","top","pop"],"arguments":[[],[-2],[-5],[-2],[],[],[],[],[],[]]}Output:[null,null,null,null,-2,-5,-2,-2,-5,-5]Explanation: The initial stack is
[-2, -5, -2]. The first popMax() removes the most recently pushed -2. The second removes the older -2 from below -5, leaving [-5]. Negative values use ordinary integer ordering.Constraints:100000 method calls occur after construction.[-1000000000, 1000000000].pop, top, peekMax, and popMax are called only when the stack is nonempty.O(1) or O(log(n + 1)) worst-case time under the standard RAM model; auxiliary space must be O(n).peekMin() -> int and popMin() -> int, also with worst-case O(log(n + 1)) time. For duplicate minimum values, popMin must remove the entry closest to the top. Explain why simply taking the smallest key in a tree ordered by (value, insertion_id) would not implement this tie-break correctly.n representing the number of profiles and a list of connections edges, return the connected components across profiles.int n, edges defined as a list of pairs representing connections.List[List[int]] — a list that contains all connected components, with each component being a list of profile IDs.0 <= n <= 20000 <= edges.length <= n * (n - 1) / 2string s, return the length of the longest substring without repeating characters.string s int — length of the longest substring without repeating characters.0 <= s.length <= 5 * 10^4s consists of English letters, digits, symbols, and spaces.null.now_ms. Times across all calls must be nondecreasing. An entry written at time t with TTL d expires at t + d, and is unavailable when now_ms >= t + d.put inserts or replaces an entry, resets its TTL, and makes it most recently used. A successful get also makes an entry most recently used but does not extend its TTL. Other operations do not change recency.cleanup returns the number of currently stored entries it expires during that call, excluding previously evicted or replaced versions. size returns the number of live entries after cleanup.MemberProfileCache(capacity: int) — create an empty cache with the specified entry limit.get(member_id: int, now_ms: int) -> Optional[str] — return a live summary and update recency, or return null.put(member_id: int, summary: str, ttl_ms: int, now_ms: int) -> None — write a summary, reset its expiration, and enforce capacity.cleanup(now_ms: int) -> int — remove expired entries and return the number removed by this call.size(now_ms: int) -> int — return the number of live entries.[ ["MemberProfileCache", [2]], ["put", [101, "Ada", 10, 0]], ["put", [202, "Ben", 20, 1]], ["get", [101, 2]], ["put", [303, "Chen", 30, 3]], ["get", [202, 4]], ["cleanup", [10]], ["size", [10]], ["get", [303, 10]] ]
[null, null, null, "Ada", null, null, 1, 1, "Chen"]
0 + 10 = 10; cleanup removes it. Member 303 expires at 3 + 30 = 33, so it remains available.Example 2:[ ["MemberProfileCache", [2]], ["put", [7, "old", 5, 0]], ["put", [7, "new", 10, 2]], ["put", [8, "other", 20, 3]], ["cleanup", [5]], ["get", [7, 5]], ["cleanup", [12]], ["get", [7, 12]], ["size", [12]] ]
[null, null, null, null, 0, "new", 1, null, 1]
2 + 10 = 12, so cleanup at 5 removes no current entries. At 12, the replacement expires; member 8 remains live until 3 + 20 = 23.Constraints1 <= capacity <= 100000; at most 200000 method calls.1 <= member_id <= 10^12; summaries contain 0–4096 characters.0 <= now_ms <= 10^15; 1 <= ttl_ms <= 10^12; calls use nondecreasing times, including repeated timestamps.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free