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.

JavaScript interview problems: pattern to techniqueRecognise the pattern to pick the technique: element transforms use map/filter/reduce; grouping uses a hash map; overlapping ranges sort then scan; matrix rotation transposes then reverses; sequential promises await in a for-of loop.Recognise the pattern firstPatternTechniqueTransform each elementmap / filter / reduceGroup or find missingHash map (object / Map)Overlapping rangesSort by start, then scanRotate a matrixTranspose + reverse rowsPromises in sequenceawait in for…of
JavaScript interview problems: pattern to technique

Array transforms — map, filter, reduce

Reach for the built-in higher-order functions before writing a manual loop.

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.

Sorting then scanning

In-place matrix manipulation

Async coordination

Objects and methods

How to use these in an interview

  1. Restate the problem and confirm edge cases (empty input, duplicates).
  2. Name the pattern — "this is a hash-map grouping problem".
  3. Write the clean version with map/filter/reduce where they fit.
  4. State complexity — time and space — without being asked.
  5. 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.


Related Posts