JavaScript Coding Interview Challenges (with Solutions)
Quick answer
The JavaScript coding problems that recur in interviews cluster into a few patterns: array transforms (map/filter/reduce), hashing for grouping and lookup (group anagrams, find the missing number), sorting-then-scanning (merge intervals), matrix manipulation (rotate an image in place), and async coordination (running promises in sequence). Recognising the pattern matters more than memorising any single solution.
A worked set of the JavaScript problems that come up most in coding interviews. Each links to a full solution with test cases; the value is in recognising which pattern each one is.
Array transforms — map, filter, reduce
Reach for the built-in higher-order functions before writing a manual loop.
- Square the numbers in an array — a direct
map. - Check a predicate holds for all elements —
Array.prototype.every.
Hashing — grouping and lookup
When a problem involves counting, grouping, or "find the missing/duplicate", a
hash map (plain object or Map) usually solves it in one pass.
- Group anagrams — key each word by its sorted letters.
- Find the missing number in an array — sum formula or a set, O(n).
Sorting then scanning
- Merge overlapping intervals — sort by start, then merge in a single scan.
In-place matrix manipulation
- Rotate an image 90° — transpose, then reverse each row; no second matrix.
Async coordination
- Run promises in sequence — await inside
for...of, or chain withreduce. NotPromise.all, which runs in parallel.
Objects and methods
- Create a User object with a password check — a method comparing an argument to a stored property.
How to use these in an interview
- Restate the problem and confirm edge cases (empty input, duplicates).
- Name the pattern — "this is a hash-map grouping problem".
- Write the clean version with
map/filter/reducewhere they fit. - State complexity — time and space — without being asked.
- Test against the tricky cases you raised in step 1.
Preparing more broadly? See the interview prep articles for language and company-specific question banks.
Key takeaways
- •Most array questions reduce to map, filter, or reduce — reach for those before writing a manual loop.
- •Grouping and 'find the missing/duplicate' problems are usually a hash map (object or Map) in one pass.
- •Merge-intervals-style problems start by sorting on the start value, then scanning once.
- •In-place matrix rotation is transpose-then-reverse-each-row — no extra matrix needed.
- •Running promises in sequence means awaiting inside a for...of or chaining reduce, not Promise.all (which runs them in parallel).
- •State the time and space complexity of your solution unprompted — interviewers expect it.
Frequently asked questions
What are the most common JavaScript coding interview questions?
Array manipulation (squaring or transforming elements, grouping anagrams), hash-map problems (the missing number in a range), interval problems (merging overlapping intervals), matrix problems (rotating an image in place), higher-order-function checks (does a predicate hold for all elements), and async questions (running promises sequentially).
How should I approach a JavaScript array problem in an interview?
First ask whether map, filter, or reduce expresses it directly — they are clearer than manual loops and signal fluency. If the problem involves lookups, counting, or grouping, reach for an object or Map for O(1) access. Then state the time and space complexity out loud.
How do you run promises sequentially in JavaScript?
Await each one inside a for...of loop, or chain them with reduce so each starts only after the previous resolves. Promise.all runs them in parallel, which is the opposite of sequential — use it only when the operations are independent.
How do you rotate a matrix in place in JavaScript?
Transpose the matrix (swap element [i][j] with [j][i]) and then reverse each row. That produces a 90-degree clockwise rotation without allocating a second matrix, in O(n^2) time and O(1) extra space.