Coding interview questions for software engineers

Coding interviews give you a problem to solve live in an editor while you talk. Interviewers watch how you clarify the problem, reach a working approach, reason about complexity and test your own code.

Software engineering loops usually mix live coding, system design and a behavioral round. Interviewers want working code you can explain, a design whose trade-offs you can defend, and stories that show ownership.

11 questions below, each one a practice interview: the AI interviewer asks it out loud, follows up on your answer, and sends you a scored feedback report.

Practise free with the AI interviewer

What the interviewer scores

  • Problem Solving

    Clarifies the problem, explores examples, reaches a working approach and reasons about its complexity before coding.

  • Correctness

    The final code solves the problem; runs pass or failures are understood and fixed.

  • Code Quality

    Readable structure, clear names, idiomatic use of the language, no needless complexity.

  • Testing & Edge Cases

    Names edge cases unprompted, tests or traces the code with examples, and fixes what testing reveals.

  • Communication

    Explains their thinking out loud, answers the question asked, checks assumptions and responds to hints and follow-ups.

Questions

Two Sum

Coding · Easy · 20 min · Free to practise

Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target.

You may assume exactly one valid answer exists, and you may not use the same element twice.

Example

Input: nums = [2, 7, 11, 15], target = 9
Output: [0, 1]

Discuss your approach out loud before coding. What is the brute-force complexity? Can you do better?

Practise this question with the AI interviewer

Design an LRU Cache

Coding · Medium · 30 min · Free to practise

Design a data structure for a Least Recently Used (LRU) cache.

Implement get(key) and put(key, value), both in O(1) average time. When the cache exceeds capacity, evict the least recently used entry.

Walk through your data-structure choices and their trade-offs before writing code.

Practise this question with the AI interviewer

Deploy Services in Dependency Waves

Coding · Medium · 30 min · Free to practise

The platform team at Larkfield Freight deploys its microservices in waves. A service may deploy only after every service it depends on has deployed in an earlier wave; all services in one wave deploy in parallel.

Write planWaves(services, dependencies):

  • services: a list of unique service names.
  • dependencies: a list of pairs [a, b] meaning a depends on b, so b must deploy first.

Return two lists: waves, the services that can deploy, grouped into as few waves as possible, each wave sorted alphabetically; and blocked, sorted, every service that can never deploy because of a dependency cycle.

Example 1

services     = ["api", "auth", "billing", "db", "web"]
dependencies = [["api","db"], ["auth","db"], ["billing","api"], ["web","api"], ["web","auth"]]
Output: waves = [["db"], ["api","auth"], ["billing","web"]], blocked = []

Example 2

services     = ["cache", "queue", "search", "worker"]
dependencies = [["queue","worker"], ["worker","queue"], ["search","queue"]]
Output: waves = [["cache"]], blocked = ["queue", "search", "worker"]

Constraints

  • Up to 100,000 services and 200,000 dependency pairs; every name in a pair is in services.
  • The same pair may appear twice, and a service may list itself.

What to discuss

Why your grouping gives the fewest waves, how you find the blocked services, and the time and space complexity. If time allows: one deploy in a wave fails. Which services in later waves must now be held back?

Practise this question with the AI interviewer

Flag Overlapping Maintenance Windows

Coding · Medium · 30 min

Cirrine Cloud schedules maintenance windows for each of its regions. Reliability rules say no more than a few regions may be in maintenance at the same time, and the scheduling team wants a tool that flags every conflict.

Write crowdedSpans(windows, k):

  • windows: a list of [region, start, end], a region name and a half-open interval [start, end) in minutes.
  • k: the threshold.

Return, sorted by start, the time spans [start, end) during which at least k distinct regions are in maintenance at once. Merge spans that overlap or touch into one. A region's own windows may overlap; a region counts once however many of its windows cover a moment.

Example 1

windows = [["east",0,60], ["east",30,90], ["west",50,120], ["north",100,150], ["north",140,160]]
k = 2
Output: [[50,90], [100,120]]

Example 2

windows = [["a",0,10], ["b",0,5], ["c",5,10]]
k = 2
Output: [[0,10]]

Constraints

  • Up to 200,000 windows; 0 <= start < end <= 10^9, integers.
  • 1 <= k <= the number of distinct regions.

What to discuss

How you order events that share a timestamp, why a region's overlapping windows need care, and your time and space complexity. Trace Example 2 out loud before you run anything.

Practise this question with the AI interviewer

Simulate a Build Farm Scheduler

Coding · Medium · 35 min · Free to practise

Quillstone's CI system runs builds on m identical machines. Each job has an id, a submit time, a duration and a priority, where a lower number is more urgent.

Whenever a machine is free and jobs are waiting, it starts the waiting job with the lowest priority number; ties go to the earlier submit time, then the smaller id. A running job is never interrupted. A machine that frees up at time t can start a job submitted at time t.

Write finishTimes(m, jobs), where each job is [id, submit, duration, priority], and return each job's finish time in the order the jobs were given.

Example

m = 2
jobs = [[1,0,5,2], [2,0,3,1], [3,1,4,1], [4,2,2,3], [5,3,1,0]]
Output: [5, 3, 8, 7, 4]

At time 3 job 2 finishes and job 5 arrives with priority 0, so it starts ahead of job 3, which has waited since time 1.

Constraints

  • Up to 200,000 jobs, not sorted by submit time; 1 <= m <= 10,000.
  • Times and durations are integers up to 10^9; durations are at least 1.

What to discuss

Which data structures you need and why, how you skip idle stretches when no job is waiting, and the complexity. If time allows: low-priority jobs can starve. How would you let a job's priority improve the longer it waits, and what does that do to your data structures?

Practise this question with the AI interviewer

Pack Records into Padded Blocks

Coding · Medium · 35 min

Bramblecode's storage engine writes records to disk in arrival order, grouped into blocks. A block holds between 1 and k consecutive records. Every record in a block is padded to the width of the widest record in that block, and every block also costs a header of h bytes. A block holding c records whose widest is w bytes therefore costs h + c * w bytes.

Write minBytes(widths, k, h) that returns the smallest total number of bytes needed to store all records. The order of records cannot change.

Example 1

widths = [4, 1, 1, 6, 6, 2], k = 3, h = 5
Output: 39

Blocks [4], [1, 1], [6, 6, 2] cost 9 + 7 + 23. Filling every block to k records costs 40.

Example 2

widths = [2, 9, 2], k = 3
h = 1  -> Output: 16 (three blocks of one)
h = 10 -> Output: 37 (one block of three)

Constraints

  • Up to 100,000 records; 1 <= k <= 200; widths and h are integers from 1 to 10^6.

What to discuss

Why a greedy rule fails, the recurrence you use, its time and memory, and the size of the answer at the limits. If time allows: also return where each block starts.

Practise this question with the AI interviewer

Find a Fair Per-Tenant Throughput Cap

Coding · Medium · 30 min · Free to practise

Fernhollow Systems runs a shared message queue that can process at most capacity messages per second across all tenants. When total demand exceeds capacity, every tenant is held to the same cap c: a tenant asking for d messages per second gets min(d, c). Small tenants are untouched, and the biggest ones absorb the shortfall.

Write fairCap(demands, capacity) that returns the largest integer c such that the tenants' total allowance, the sum of min(d, c), does not exceed capacity. If total demand already fits, return -1: no cap is needed.

Example 1

demands = [120, 40, 300, 75], capacity = 400
Output: 165

With c = 165 the allowances are 120, 40, 165 and 75, which sum to 400. With 166 they sum to 401.

Example 2

demands = [5, 5, 5], capacity = 2
Output: 0

Constraints

  • Up to 100,000 tenants; each demand is an integer from 1 to 10^9; capacity is up to 10^14.

What to discuss

What property of the problem lets you search for c instead of trying every value, your complexity, and the overflow risks. If time allows: demands change every second, one tenant at a time. How would you keep the cap current without recomputing from scratch?

Practise this question with the AI interviewer

Build an HTTP Route Matcher

Coding · Hard · 45 min · Free to practise

Your team is building the request router for an in-house web framework. Implement a router with two operations:

  • addRoute(pattern, handler): register a pattern such as /users/:id/files/*path. A segment is a literal (users), a parameter (:id, which matches exactly one segment) or a catch-all (*path, allowed only as the last segment, which matches one or more remaining segments). Registering a pattern with the same shape as an existing one (/users/:id and /users/:uid) is an error.
  • match(path): return the handler and the captured values, or nothing when no route matches.

When several routes match, compare them segment by segment from the left: at the first segment where they differ, a literal beats a parameter, which beats a catch-all.

Example

addRoute("/users/me", "currentUser")
addRoute("/users/:id", "userById")
addRoute("/users/:id/files/*path", "userFile")
addRoute("/users/me/settings", "mySettings")

match("/users/me")                  -> currentUser, {}
match("/users/42")                  -> userById, {id: "42"}
match("/users/me/files/docs/cv.pdf") -> userFile, {id: "me", path: "docs/cv.pdf"}
match("/users/42/files")            -> no match

Constraints

  • Up to 10,000 routes and 100,000 match calls; paths start with /, have at most 20 segments and no empty segments.

What to discuss

Your data structure, how matching recovers when a more specific branch dead-ends, and the worst-case cost of a match. Part two: the router must serve a million matches per second while routes are reloaded every few minutes. Can you bound the worst case, and how do readers stay safe during a reload?

Practise this question with the AI interviewer

Count Network Groups After Fiber Cuts

Coding · Hard · 45 min

Veltrane runs a data center with n racks, numbered 0 to n - 1, joined by fiber links. After an outage, the incident report lists the links that were cut, in the order they were cut. The reliability team wants to know how fragmented the network was after each cut.

Write groupsAfterCuts(n, links, cuts):

  • links: a list of pairs [u, v], each a link between two racks.
  • cuts: indexes into links, in the order the links were cut. Each link is cut at most once.

Return a list with one entry per cut: the number of connected groups of racks right after that cut.

Example

n = 5
links = [[0,1], [1,2], [2,0], [3,4], [2,3]]
cuts  = [4, 0, 1]
Output: [2, 2, 3]

Cutting link 4 splits {0,1,2} from {3,4}. Cutting link 0 changes nothing, since 0 and 1 still meet through 2. Cutting link 1 isolates rack 1.

Constraints

  • n up to 100,000; up to 200,000 links, which may include parallel links between the same racks.

What to discuss

Why removing links is harder than adding them, how you avoid recomputing the groups after every cut, and your complexity. Part two: cuts now arrive live and you must answer each one before you see the next. What changes, and what can you still do better than a full recount?

Practise this question with the AI interviewer

Design a Live Contest Leaderboard

Coding · Hard · 45 min

Puzzlevine runs weekly programming contests and needs a live leaderboard. Implement a class with these operations:

  • submit(player, points): add points (an integer from 1 to 100) to the player's score; a new player starts at 0.
  • rank(player): 1 plus the number of players with a strictly higher score, so tied players share a rank; -1 for an unknown player.
  • top(k): the k best players as (player, score) pairs, highest score first, ties broken by player name.
  • remove(player): delete the player from the leaderboard.

Example

submit("ana", 50); submit("bo", 80); submit("cy", 50); submit("dee", 20)
rank("bo") -> 1   rank("ana") -> 2   rank("cy") -> 2   rank("dee") -> 4
top(3)     -> [("bo",80), ("ana",50), ("cy",50)]
submit("dee", 40)
rank("dee") -> 2  rank("ana") -> 3
remove("bo")
rank("dee") -> 1  rank("bo") -> -1

Constraints

  • Up to 100,000 players and 1,000,000 operations; a player submits at most 10,000 times; k <= 100.
  • rank and top must be much faster than scanning every player.

What to discuss

The structures you choose and the cost of each operation, and how your choice depends on the score range. Part two: the contest grows to ten million players across many servers. Exact ranks are needed only for the top 1,000; everyone else may see an approximate rank. How would you design that?

Practise this question with the AI interviewer

Evaluate Access Policy Expressions

Coding · Hard · 45 min · Free to practise

Merrowgate's internal tools decide who may open an admin page by evaluating policy expressions against the signed-in user's attributes. Write evaluate(expression, attributes) that returns true or false, or signals an error.

The language:

  • A comparison name op value, where op is one of == != < <= > >= and value is a double-quoted string (no escapes) or a non-negative integer.
  • A bare attribute name, used as a boolean, and the literals true and false.
  • not, and, or (binding in that order, tightest first) and parentheses.
  • attributes maps names to strings, integers or booleans. A missing attribute makes its comparison, or its bare use, false.
  • A syntax error, comparing different types, or ordering (<, >...) strings or booleans is an error whose message says where it happened.

Examples

role == "admin" or team == "billing" and level >= 3
  with {role: "admin", team: "support", level: 1}       -> true

not (suspended or level < 2)
  with {level: 5, suspended: false}                    -> true

level >= "3"
  with {level: 4}                                      -> error: type mismatch

Constraints

  • Expressions are up to 2,000 characters and may nest parentheses up to 50 deep.

What to discuss

How you split tokenizing, parsing and evaluating, how precedence falls out of your design, and your tests. Part two: 500 policies are evaluated millions of times a minute against different users. What would you do once, and what per request? Does short-circuiting hide errors on the right-hand side, and is that acceptable?

Practise this question with the AI interviewer