Problem Library
Browse standard JavaScript & TypeScript interview questions and code review tasks
Valid Parentheses
EasyGiven a string `s` containing just the characters `'('`, `')'`, `'{'`, `'}'`, `'['` and `']'`, determine if the input string is valid. An input string is valid if: 1. Open brackets must be closed by the same type of brackets. 2. Open brackets must be closed in the correct order. 3. Every close bracket has a corresponding open bracket of the same type.
Two Sum
EasyGiven an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`. You may assume that each input would have exactly one solution, and you may not use the same element twice.
Reverse Linked List
EasyGiven the head of a singly linked list, reverse the list, and return the reversed list.
Implement Debounce
EasyImplement a `debounce` function that delays invoking `fn` until after `delay` milliseconds have elapsed since the last time the debounced function was invoked.
Flatten Array (Deep)
EasyWrite a function `flatten` that recursively flattens a nested array of arbitrary depth without using `Array.prototype.flat`.
Implement Memoize
EasyImplement a `memoize` function that takes a function `fn` and returns a memoized version that caches results based on arguments stringification.
Group By Polyfill
EasyWrite a method or function `groupBy(array, fn)` that splits an array into an object grouped by the key returned from `fn(item)`.
Code Review: Inefficient API Implementation
EasyCode ReviewReview the following search API route handler. Identify unnecessary work, missing database pagination, over-fetching raw data, and security exposures.
Code Review: Bad TypeScript Design
EasyCode ReviewReview the following TypeScript data mapper. Identify type safety flaws, excessive `any` usage, unsafe type assertions (`as any`), and weak interfaces. Refactor for strict type safety.
Code Review: Poor Logging & Error Design
EasyCode ReviewReview the following checkout payment gateway integration. Identify security logging violations, swallowed errors, lack of contextual logging, and leaking internal database stack traces to clients.
Three Sum
MediumGiven an integer array `nums`, return all the triplets `[nums[i], nums[j], nums[k]]` such that `i != j`, `i != k`, and `j != k`, and `nums[i] + nums[j] + nums[k] == 0`. Notice that the solution set must not contain duplicate triplets.
Implement Promise.all
MediumImplement a custom `promiseAll` function that accepts an array of promises (or values) and returns a single Promise that resolves to an array of results, maintaining original order. If any promise rejects, `promiseAll` rejects with that error immediately.
Implement Throttle
MediumImplement a `throttle` function that creates a throttled function that only invokes `fn` at most once per every `limit` milliseconds.
LRU Cache
MediumDesign a data structure that follows the constraints of a Least Recently Used (LRU) cache. Implement the `LRUCache` class: - `LRUCache(capacity)` Initialize the LRU cache with positive size capacity. - `get(key)` Return the value of key if it exists, otherwise return -1. - `put(key, value)` Update or insert the value. When capacity is reached, invalidate the least recently used item.
Longest Substring Without Repeating Characters
MediumGiven a string `s`, find the length of the longest substring without repeating characters.
Custom Event Emitter
MediumDesign an `EventEmitter` class with `subscribe(eventName, callback)` and `emit(eventName, args)` methods. `subscribe` should return an unsubscribe handle object with an `unsubscribe()` method.
Deep Clone Object
MediumWrite a function `deepClone(obj)` that returns a deep copy of an object or array, handling primitives, nested objects, arrays, and dates without using `structuredClone` or `JSON.parse(JSON.stringify(obj))`.
Implement Currying
MediumWrite a function `curry(fn)` that transforms a function `fn` that accepts multiple arguments into a function that can be called repeatedly with single or multiple arguments until all expected arguments are provided.
Code Review: N+1 Database Queries
MediumCode ReviewReview the following user profile enrichment service. Identify performance issues (specifically N+1 database query patterns), explain the architectural impact on database connection pools, and propose an optimized batching/joining solution.
Code Review: Async Error Handling
MediumCode ReviewReview the following payment notification pipeline. Identify problematic async behavior, missing error handling, floating unawaited promises, and failure propagation issues.
Code Review: Promise Concurrency Exhaustion
MediumCode ReviewReview the following batch notification dispatcher. Identify why firing thousands of HTTP requests with unrestricted `Promise.all()` leads to socket exhaustion, memory spikes, and API rate limit bans. Refactor with controlled concurrency.
Code Review: Authorization & Security Bug
MediumCode ReviewReview the following document sharing API endpoint. Identify the critical security flaw (Insecure Direct Object Reference - IDOR), explain how an attacker could exploit it, and implement proper authorization checks.
Code Review: Overengineered Code
MediumCode ReviewReview the following user name formatting module. Identify unnecessary design abstractions, premature generalization, and refactor it into a clean, simple, readable function.
Implement Concurrency Limiter
HardImplement a `ConcurrencyLimiter` class (or function) that manages async task execution, ensuring that no more than `maxConcurrency` tasks run simultaneously while queueing additional tasks.
Code Review: Race Condition & State Mutability
HardCode ReviewReview the following wallet balance transfer handler. Identify how concurrent operations produce inconsistent state, explain the race condition window, and refactor using atomic operations or database transactions.
Code Review: Node.js Memory Leak
HardCode ReviewReview the following WebSocket stream manager and query cache. Identify why process memory grows continuously over time, locate uncleaned event listeners/timers, and propose a leak-free implementation.