LinkedIn logo

LinkedIn Hard Interview Questions

7 hard-level practice questions for LinkedIn technical interviews

LinkedIn software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer
coding Hard Verified Question #1

1. [OA] Minimum Weight Ceiling Path


Category: Graph coding problem
A network topology connects 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)
Output: Integer
Want to practise this one?
Create a free account to open the full question and practise LinkedIn questions with AI.
Sign up free
coding Hard Verified Question #2

2. Priority Cache System


Category: String coding problem
A CDN (Content Delivery Network) maintains a fixed-capacity cache of web content. Each content item has an associated priority score. When the cache...
Input: String
Output: Integer
coding Hard Verified Question #3

3. Combine N-ary Trees


Category: Tree coding problem
You are given the roots of two N-ary organization charts, each representing a hierarchical department structure. Every node has an integer...
Input: List
Output: Computed result
coding Hard stack queue #1

1. [Stack and Balanced Tree] — Implement a Max Stack with worst-case operation bounds


Background
LinkedIn's infrastructure tooling can need both arrival-order access to pending diagnostic events and priority-based access to the most severe event. A max stack models these two access patterns; this data-structure question was reported in a LinkedIn Staff SWE interview in November 2025.
Problem statement
Implement a MaxStack storing integer values. It must support ordinary last-in, first-out stack operations as well as inspecting and removing the maximum value anywhere in the stack.
If several entries share the maximum value, popMax must remove the one closest to the top of the stack. Removing that entry must preserve the relative stack order of all remaining entries. Duplicate and negative values are allowed.
Every operation must take O(1) or O(log n) worst-case time, where n is the current number of entries. An implementation relying on amortized cleanup of stale heap entries does not satisfy this requirement. Use O(n) auxiliary space.
Function or class signature
  • 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.


Example 1:
Input:
{"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:
  • At most 100000 method calls occur after construction.

  • Values are integers in the inclusive range [-1000000000, 1000000000].

  • pop, top, peekMax, and popMax are called only when the stack is nonempty.

  • Calls are single-threaded.

  • Each public operation must run in O(1) or O(log(n + 1)) worst-case time under the standard RAM model; auxiliary space must be O(n).


Follow-up:
Add 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.
Want to practise this one?
Create a free account to open the full question and practise LinkedIn questions with AI.
Sign up free
coding Hard graph #2

2. [OA] Depth First Search — Find all connected components in a network of LinkedIn profiles

LinkedIn's algorithm can identify connections between users to enhance networking. We want to find all connected components given a list of connections between user profiles.
Problem statement: Given an integer n representing the number of profiles and a list of connections edges, return the connected components across profiles.
  • Input: int n, edges defined as a list of pairs representing connections.

  • Output: List[List[int]] — a list that contains all connected components, with each component being a list of profile IDs.


Example 1:
Input: n = 5, edges = [[0, 1], [1, 2], [3, 4]]
Output: [[0, 1, 2], [3, 4]]
Explanation: Profile 0 is connected to 1 and 2; profile 3 is connected to 4.
Example 2:
Input: n = 4, edges = [[0, 1], [1, 0], [2, 3]]
Output: [[0, 1], [2, 3]]
Constraints:
  • 0 <= n <= 2000

  • 0 <= edges.length <= n * (n - 1) / 2
coding Hard sliding window #3

3. [OA] Sliding Window — Implement a feature to find the longest substring without repeating characters in profile descriptions

LinkedIn users often write descriptive profiles, and analyzing these descriptions can help in improving user engagement. The goal is to identify the longest substring from a given profile description where no characters are repeated.
Problem statement: Given a string s, return the length of the longest substring without repeating characters.
  • Input: string s

  • Output: int — length of the longest substring without repeating characters.


Example 1:
Input: "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
Example 2:
Input: "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.
Constraints:
  • 0 <= s.length <= 5 * 10^4

  • s consists of English letters, digits, symbols, and spaces.
system design Hard caching #4

4. Design MemberProfileCache — a bounded LRU cache with per-entry expiration


Background
LinkedIn surfaces member profile summaries in search results, connection suggestions, and messaging. Model an in-process cache of serialized profile-summary projections so repeated reads avoid fetching the projection again, while per-entry expiration bounds how long an old projection remains cached. This exercise adapts a reported LinkedIn LRU-with-TTL interview question; it does not claim to reproduce LinkedIn's production implementation.
Requirements
1. Construct a cache with a positive entry capacity. Each entry maps a positive member ID to a serialized profile-summary string; a missing or expired entry returns null.
2. Every operation receives an explicit integer 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.
3. Before performing any operation, remove all expired entries. 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.
4. If inserting an entry would exceed capacity after expiration cleanup, evict the least recently used live entry. Replacing an existing member must not evict another live entry. Old expiration records must never delete a newer replacement.
5. 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.
6. Avoid scanning every live entry on every operation. Maintain O(capacity) storage, including expiration metadata; amortized occasional rebuilding of metadata is allowed. Implement a single-threaded class, not a distributed architecture.
Class API
  • 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.


Example 1:
Input sequence:
[
  ["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]]
]

Output, with one result per call:
[null, null, null, "Ada", null, null, 1, 1, "Chen"]

Explanation: Reading member 101 makes member 202 least recently used, so inserting member 303 evicts member 202. Member 101 expires exactly at 0 + 10 = 10; cleanup removes it. Member 303 expires at 3 + 30 = 33, so it remains available.
Example 2:
Input sequence:
[
  ["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]]
]

Output:
[null, null, null, null, 0, "new", 1, null, 1]

Explanation: The original version of member 7 expired at 5, but it was replaced. Its replacement expires at 2 + 10 = 12, so cleanup at 5 removes no current entries. At 12, the replacement expires; member 8 remains live until 3 + 20 = 23.
Constraints
  • 1 <= 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.

  • Inputs satisfy these bounds. Calls are single-threaded; no background worker or real-time clock is required.

  • Capacity limits entries, not bytes. O(capacity) storage refers to metadata and stored entries, excluding the variable length of their string payloads.

Start practicing LinkedIn questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free