30 backtracking interview questions, asked at Meta, Google, Amazon and 9 more companies. Last asked Oct 2026.
+1
URL router with single-segment wildcardsCodingBuild a small URL router. - A pattern and a path are split on / into segments. Empty segments are ignored, so /a/b/ is the same as /a/b, and / is the empty path. - A p
Last asked Oct 2026
Collect the characters along a path in a gridCodingA 2D grid has one path that starts at (0, 0); path cells hold either or a letter, and other cells are empty. Follow the path and return the letters on it, in order, as a string…
Last asked Aug 2026
Choose words with no shared letters to cover the most lettersCodingGiven a list of lowercase words, pick a subset in which no letter appears twice across the chosen words, maximizing the number of distinct letters covered. Start with a correct…
Last asked Aug 2026
Design a distributed crossword solverSystem designGiven a large crossword grid with about a hundred slots and a dictionary of around a million words, design a service that fills the grid. One machine cannot search the space fast…
Last asked Aug 2026
Count simple paths whose labels match a prefixCodingEvery node of a graph carries a label. Count the simple paths (paths that never repeat a node) whose sequence of labels matches a given prefix string. Explain how you prune the…
Last asked Aug 2026
Count legal tic-tac-toe game sequencesCodingCount the legal game sequences on tic-tac-toe boards, including a 4x4 three-in-a-row variant, enumerating valid play orders with backtracking. Reported on 1point3acres' Decagon…
Last asked Jul 2026
Every ordered sum of 1s and 2s that makes nCodingGiven n, list every ordered sequence of 1s and 2s that adds up to n (so 1+2 and 2+1 are different), and say how many there are.
Last asked Jun 2026
Three-color map coloringCodingYou are given a map as a list of location names, locations, and a list of pairs, adjacencies. Each pair a, b means locations a and b share a border. Implement colormap(locations…
Last asked Jun 2026
Resolve package versions from dependency constraintsCodingPackages have versions, and each version may require other packages within a version range. Parse the dependency specs, answer queries about which versions satisfy a constraint…
Last asked May 2026
Every cheapest way to order from a combo menuCodingA food ordering app wants to show a customer every cheapest way to buy the dishes they want. The menu is a list of entries. Each entry is (id, price, items): - id: a unique…
Last asked May 2026
Does a word exist as a path in a graph?CodingEvery node of a graph holds a letter. Decide whether a word can be spelled by walking along edges, one letter per node. Agree on whether a node may be used twice, and give the…
Is a 14-tile mahjong hand a winning hand?CodingGiven 14 mahjong tiles, decide whether they form a winning hand: four sets, each three identical tiles or three consecutive tiles of the same suit, plus one pair.
Last asked Mar 2026
Letter combinations of a phone numberCodingEach digit from 2 to 9 on a phone keypad stands for a few letters. Given a string of digits such as "2345", list every letter string it can spell and say how many there are.
Last asked Mar 2026
Generate all permutationsCodingReturn every ordering of a list of distinct numbers using backtracking. Follow-ups may include input with duplicates (skip repeats) and the time cost. In the reported round a…
Last asked Mar 2026
Settle group debts with the fewest transfersCodingA group of people owe each other money, given as transfers (from, to, amount). Return the smallest number of transfers that brings every person's balance to zero.
Last asked Feb 2026
Word break II: every way to split a sentenceCodingGiven a string and a dictionary of words, return every sentence you can form by splitting the string into dictionary words, with words separated by spaces. Words may be reused…
Last asked Jan 2026
All subsets of a list with duplicatesCodingReturn every distinct subset of an integer list that may contain duplicate values, with no subset repeated. Sort first and skip duplicates during backtracking, and give the output…
Last asked Jan 2026
Insert plus or minus signs between digits to reach a targetCodingGiven a string of digits and a target, insert +, - or nothing between consecutive digits so the expression equals the target, and return every such expression. Handle numbers with…
Last asked Dec 2025
Settle group trip expenses with the fewest transfersCodingFriends on a trip record payments: each record names the payer, the amount and the people it covered (the payer may be among them), split evenly. Compute each person's net…
Last asked Nov 2025
Find a target in an unknown grid with a robot APICodingA robot sits somewhere in a grid you cannot see: you don't know its size, its walls or where you start. You can only call the robot's API: move forward (which reports whether it…
Last asked Nov 2025
Subsets, with and without backtrackingCodingReturn every subset of a set of distinct numbers using backtracking, then write it again iteratively, without backtracking, by building subsets up or using bit masks. Reported in…
Last asked Sep 2025
Permutations of a list with duplicatesCodingReturn every distinct ordering of a list that may contain repeated values, with no duplicate orderings in the output. Sort first and skip a value at a position when an equal value…
Last asked Sep 2025
Expression add operatorsCodingGiven a string of digits and a target, insert +, - or between digits so that the expression evaluates to the target, and return every such expression. Handle multiplication…
Last asked Aug 2025
Robot room cleanerCodingA cleaning robot is placed in an unknown room with obstacles. Using only move(), turnLeft(), turnRight() and clean(), clean every reachable cell. Explore by depth-first search…
Last asked Aug 2025
Fill a weekly work schedule to an exact hour totalCodingA week's work plan is written as a 7-character string pattern, one character per day. A digit (0-9) is a day whose hours are already set. A ? is a day that is still open…
Fit the most tasks into an hour across machine slotsCodingYour team runs a batch cluster of n machines with IDs 0 to n-1. Each machine has m execution slots, so it can run up to m tasks at the same time. A slot runs one task at a time;…
+1
Multi-tap keypad: every string a press sequence can spellCodingAn old phone types letters by multi-tap: pressing a key once gives its first letter, twice in a row gives its second letter, and so on. Use this keypad: Key Letters ------ 1 A B C…
Spell a word with letter blocks, one block per letterCodingYou have a set of letter blocks. Each block is a list of lowercase characters printed on its faces. You also get a target string. Implement canform(blocks: listliststr, target:…