Practice problems
Choose a topic, work through an example, and reveal a hint or worked answer when you’re ready.
Showing 61–80 of 145 problems
Optional chaining and missing values
What value does the expression produce?
Closures and private function state
What does b return on its first call?
Objects, prototypes, and this
Which object does this refer to inside label?
The event loop and microtasks
What order do the logs appear in?
Iterables and generators
What array does [...generator()] produce?
Web workers and message passing
Which side should update the heading with the total?
Memory and event listener cleanup
What should happen when the view closes?
Coordinating multiple promises
In what order do the results appear?
Arrays and prefix sums
Find the sum of the supplied zero-based interval. Include both endpoints.
Big O and growth
Two independent loops each visit every item in a list. Count the total visits and give the time bound.
Linear search
Find the first shelf position with the requested label. Use zero-based indexing and -1 for a missing label.
Binary search
A library shelf displays sorted copy numbers. Return the zero-based index of a requested number, or -1 if the copy is absent.
Bubble sort
Show the array after exactly one full pass of bubble sort, starting on the left.
Stacks and undo
Read the top value after performing the listed operations, or return "Empty".
Queues and arrival order
List the jobs removed in order. Return "Empty" for a removal when no job is waiting.
Two pointers
Which distinct pair reaches the target?
Sliding windows
What is the largest window sum?
Singly linked lists
Insert B after A and report the resulting node order.
Hash maps and counting
Return the first label seen a second time, or "None" if all labels are unique.
Recursion and tree traversal
Count all nodes in each tree. A missing child contributes zero.