Your progress

0 / 0

In-order Traversal

Receives an array of integers and interprets it as a binary tree laid out level-order — index i's children live at 2i+1 and 2i+2, the same indexing scheme used by binary heaps. It then walks the tree recursively in-order: fully visit the left subtree, process the current node, then fully visit the right subtree. Returns a new array with the values in the order they were visited. Unlike a binary search tree, this tree has no ordering property, so the result is not necessarily sorted — it reflects the tree's shape, not the values themselves.

Easy Trees

Level-order Traversal

Receives an array of integers and interprets it as a binary tree laid out level-order — index i's children live at 2i+1 and 2i+2, the same indexing scheme used by binary heaps. It then walks the tree breadth-first with a queue: starting from the root, each pass drains every node currently in the queue into one result row while enqueuing their children for the next pass. Returns an array of arrays, one per depth level (shallowest first), each holding that level's node values left to right.

Medium Trees

Remove Duplicates (Doubly Linked List)

Receives an array of integers and builds a doubly linked list, where each node holds a value, a next pointer to the following node, and a prev pointer to the preceding one. It walks the list forward from head to tail using a set to track seen values; the first occurrence of each value is kept and any duplicate node is unlinked by updating both its predecessor's next and its successor's prev. Returns the head of the filtered list with each value appearing exactly once, preserving the original order.

Easy Lists

Remove Duplicates (Circular Linked List)

Receives an array of integers and builds a circular linked list, where each node holds a value and a next pointer — and the last node's next points back to the head instead of null. It walks the list starting from head's successor using a while loop that stops when it reaches head again, tracking seen values with a set; the first occurrence of each value is kept and any duplicate node is unlinked by redirecting its predecessor's next. Returns the head of the filtered circular list with each value appearing exactly once, preserving the original order.

Medium Lists

String Decoder

Receives a string encoded in the run-length format n[substring], where a number followed by a bracketed group means that group repeats n times, and groups can be nested. It scans the text left to right with a stack: digits build the repeat count, an opening bracket pushes the text built so far together with its count, plain letters are appended to the current text, and a closing bracket pops the saved text and count to repeat the just-finished group — expanding the innermost groups first. Returns the fully expanded string; text without brackets is returned unchanged and an empty input yields an empty string.

Medium Text

Quicksort

Receives an array of integers and sorts it in ascending order using quicksort, a divide-and-conquer algorithm. For each range it picks a pivot (the last element) and partitions the range so that every value smaller than the pivot ends up to its left and every larger-or-equal value to its right; the pivot then sits in its final sorted position. The two sides are sorted the same way recursively until every range has at most one element. Returns a new array with the values in ascending order.

Medium Sorting

Valid Parentheses

Receives a string and checks whether its brackets are balanced and correctly nested. The valid pairs are (), [] and {}; any other character (letters, spaces, digits) is ignored. It scans the string left to right with a stack: every opening bracket is pushed, and every closing bracket must match the bracket on top of the stack — if it matches, that opening bracket is popped, otherwise the string is unbalanced. After the scan the string is balanced only if the stack is empty (no opening bracket was left unclosed). Returns true when every bracket is correctly paired and nested, and false otherwise.

Easy Text

Running Average

Receives an array of integers and a window size w. It computes the average of every consecutive block of w elements: instead of re-adding each window from scratch, it keeps a running sum and slides the window one position at a time — adding the value that enters on the right and subtracting the one that leaves on the left — so the whole pass costs O(n). Each average is rounded to two decimals. Returns an array with one average per window, in order; if w is larger than the array (or not positive) it returns an empty array, and when w equals the array length it returns a single average.

Easy General

Most Frequent Elements

Receives an array of integers and a number k, and returns the k most frequent values ordered from highest to lowest frequency. It runs in O(n) using bucket sort: first it counts every value's frequency in a hash map, then it scatters each value into a bucket indexed by its frequency (so all values that appear the same number of times share a bucket), and finally it reads the buckets from the highest frequency down, collecting values until it has k of them. Returns a new array with the k most frequent values, most frequent first; when several values tie in frequency any order between the tied ones is valid. If k is greater than or equal to the number of distinct values it returns every distinct value, and an empty input yields an empty array.

Medium Hashing

Bubble Sort

Receives an array of integers and sorts it in ascending order using bubble sort. It makes repeated passes over the unsorted portion: on each pass it compares every adjacent pair — if the left value is greater than the right, they are swapped — so the largest unsorted value bubbles to its final position at the end. Each subsequent pass covers one fewer element because the last position of the previous pass is already settled; an early-exit check stops the algorithm as soon as a full pass makes no swaps, because the array is already in order. Returns a new array with the values in ascending order.

Easy Sorting

Matrix Spiral

Receives an N×M matrix of integers and returns all of its elements in clockwise spiral order, starting from the top-left corner. It keeps four boundary pointers — top, bottom, left and right — and on each lap walks the top row left to right, the right column top to bottom, the bottom row right to left, and the left column bottom to top, shrinking the matching boundary inward after each side. It repeats until the boundaries cross, so every cell is visited exactly once. Returns a new array with the values in spiral order; an empty matrix yields an empty array, a single row is returned left to right, and a single column top to bottom.

Medium Matrices

Two Sum

Receives an array of integers and a target value, and returns the indices of the two numbers that add up to the target. It scans the array once, keeping a hash map from each value seen so far to its index: at each element it computes the complement (target minus the current value) and checks whether that complement is already a key in the map — if so, the pair is found immediately; otherwise the current value is recorded in the map and the scan continues. This trades a little extra memory for speed, running in O(n) instead of the O(n²) of checking every pair. Returns a new array with the two matching indices in the order [earlier, later]; returns an empty array when no such pair exists.

Easy Hashing

Reverse String

Receives a string of text and returns its characters in reverse order. It uses the classic two-pointer technique: one pointer starts at the beginning, the other at the end, and on each step they swap the characters they point to, then move one position toward each other. This continues until the pointers meet (an odd-length string leaves its middle character untouched) or cross (an even-length string has every character swapped). The whole string is reversed in place in O(n) time using only two extra variables. Returns a new string with the characters in reverse order; an empty or single-character string is returned unchanged.

Easy Text

Palindrome Check

Receives a string of text and checks whether it reads the same forwards and backwards. It uses the classic two-pointer technique: one pointer starts at the beginning, the other at the end, and on each step they compare the characters they point to. As soon as a pair does not match, the string cannot be a palindrome and the check stops immediately; otherwise both pointers move one position toward each other until they meet (an odd-length string leaves its middle character unchecked) or cross (an even-length string has every pair compared). The comparison is case-sensitive and exact — no letters, spaces or punctuation are ignored. Returns true when every pair of characters matches, and false otherwise.

Easy Text

Fibonacci

Receives a non-negative integer n and returns the n-th Fibonacci number, where fib(0) = 0, fib(1) = 1, and every later term is the sum of the two before it (fib(k) = fib(k-1) + fib(k-2)). It computes the answer via top-down recursion: fib(n) calls fib(n-1) and fib(n-2), which in turn call their own smaller sub-problems, down to the base cases 0 and 1. A memo (a map from index to its already-solved value) records every sub-problem's result the first time it is solved, so a later call for the same index returns instantly instead of recomputing it — turning the naive exponential recursion into O(n) time and space. Returns the single integer fib(n); n ≤ 0 returns 0 directly, with no recursion.

Easy Recursion

Binary Search on a Rotated Array

Receives an array of integers that was sorted in ascending order and then rotated at an unknown pivot (e.g. [4,5,6,7,0,1,2]), plus a target value. At each step it looks at the middle element and first figures out which half of the current range — left or right — is still contiguously sorted by comparing the boundary values; then it checks whether the target falls inside that sorted half's value range to decide whether to keep searching there or move to the other half, halving the range each step. Returns the index (position) where the target is found, or -1 if it is not present.

Medium Searching

Climbing Stairs

Receives a non-negative integer n, the number of stairs in a staircase, and returns the number of distinct ways to reach the top when each move is either 1 or 2 steps. It computes the answer with bottom-up dynamic programming: the number of ways to reach step k is the sum of the ways to reach the two steps before it (ways(k) = ways(k-1) + ways(k-2)), so it fills that recurrence iteratively from the base cases ways(0) = ways(1) = 1 up to n, using two rolling variables instead of recursion. Returns the single integer ways(n); n ≤ 1 returns 1 directly (a staircase of zero or one step has exactly one trivial way to climb it).

Easy Dynamic Programming

Maximum Subarray

Receives an array of integers and returns the sum of the contiguous subarray with the largest sum. It solves this with Kadane's algorithm — a single dynamic-programming pass that, at each index, decides whether extending the running subarray from the previous index is better than starting a new one at the current element (currentSum = max(arr[i], currentSum + arr[i])), while separately tracking the best sum seen so far. Returns that single integer, the largest sum of any contiguous subarray; an empty array returns 0.

Medium Dynamic Programming

Coin Change

Receives an array of coin denominations and a target amount, and returns the minimum number of coins needed to make that amount, or -1 if it cannot be made with the given coins. It solves this with bottom-up dynamic programming: a table dp[0..amount] tracks the minimum coins needed for every amount from 0 up to the target, seeded with the base case dp[0] = 0. For each amount i from 1 to the target, it tries every coin denomination no larger than i — if using that coin (dp[i - coin] + 1) needs fewer coins than the best found so far for i, dp[i] is updated. Returns dp[amount], or -1 if it stayed unreachable (no combination of the given coins sums exactly to the target).

Medium Dynamic Programming

BFS Graph

Traverses a graph breadth-first starting from node 0, using an explicit FIFO queue: it visits the start node, then all of its direct neighbors, then their unvisited neighbors, expanding outward one ring at a time — the same building block used to find shortest paths in unweighted graphs. Receives the graph as a square adjacency matrix, where a nonzero value at row i, column j marks an edge between nodes i and j (0 means no edge). Returns the node indices in the order they were visited; nodes unreachable from node 0 are never visited.

Medium Graphs

DFS Graph

Traverses a graph depth-first starting from node 0, using an explicit LIFO stack: it visits the start node, dives into one unvisited neighbor as deep as possible, then backtracks to explore the next one — the same building block used to detect cycles and find connected components. Receives the graph as a square adjacency matrix, where a nonzero value at row i, column j marks an edge between nodes i and j (0 means no edge). Returns the node indices in the order they were visited; nodes unreachable from node 0 are never visited.

Medium Graphs

Min-Heap

Rearranges an array of integers into min-heap order using Floyd's bottom-up build-heap algorithm: the array is read as a complete binary tree, where the value at index i has children at 2i + 1 and 2i + 2, and every parent must be less than or equal to both of its children. Starting from the last parent node and working back to the root, each subtree is sifted down — swapping a parent with its smallest child until the property holds or a leaf is reached. Returns a new array satisfying the min-heap property, the structure behind priority queues and efficient min/max retrieval.

Medium Heaps

Count Bits

Receives a non-negative integer n and returns the number of 1 bits (its population count, or Hamming weight) in n's binary representation. It applies Brian Kernighan's trick: repeatedly AND the running value with itself minus one, which clears exactly its current lowest set bit on every pass, so the loop runs once per set bit instead of once per bit position. Returns that count as a single integer — O(popcount) time, O(1) extra space; n ≤ 0 returns 0 directly, with no iterations.

Easy Bit Manipulation

LRU Cache

Receives a cache capacity and a sequence of put/get operations (semicolon-separated put:key:value / get:key commands) and replays that sequence against a Least Recently Used cache built with that capacity. It maintains the cache as a hash map (key to node) paired with an explicit doubly linked list ordered from most- to least-recently-used: every get moves the accessed key to the front (or returns -1 if the key is absent), and every put either updates and moves an existing key to the front or inserts a new one at the front, evicting the entry at the back (the least recently used) whenever this pushes the cache past capacity — giving O(1) time for both operations. Returns the ordered results of each get command in the sequence, using -1 for a cache miss.

Hard Hashing

Word Search

Receives a rectangular grid of single letters and a target word, and returns whether the word can be traced through the grid by moving to horizontally or vertically adjacent cells, never reusing the same cell twice within one trace. From every cell it tries a depth-first search that matches the word letter by letter, marking each cell used along the current path and unmarking it (backtracking) whenever a path dead-ends, so a failed attempt never blocks a different starting cell or direction from reusing that cell. Returns true as soon as one full trace matches the word; returns false only after every starting cell and every direction has been exhausted. An empty word is trivially found (true); an empty grid cannot contain any word (false).

Hard Matrices New

Shortest Path (Dijkstra)

Computes the shortest distance from node 0 to every other node in a weighted graph using Dijkstra's algorithm. Repeatedly picks the unvisited node with the smallest known distance, marks it settled, then relaxes every edge leaving it — lowering a neighbor's tentative distance whenever a shorter path is found through the current node — until every reachable node has its final, minimum distance. Receives the graph as a square adjacency matrix, where a positive value at row i, column j is the weight of an edge between nodes i and j (0 or negative means no edge; weights must be non-negative for the algorithm to be correct). Returns the shortest distance from node 0 to every node, using -1 for a node that cannot be reached at all.

Hard Graphs New

Serialize / Deserialize Binary Tree

Receives an array of integers and builds a binary search tree from them (duplicates ignored), exactly like the Binary Search Tree exercise. It then serializes that tree into a single string by walking it in preorder — the node itself first, then its left subtree, then its right — writing each node's value as a token and a "#" token wherever a child is missing, so the tree's exact shape survives the trip. It parses that same string back into a brand-new tree by consuming the tokens in the same preorder sequence, then reads the rebuilt tree back out in preorder. Returns that final preorder array, which — if serialization and deserialization are correct — is identical to the preorder of the tree that was originally built.

Hard Trees New

Trapping Rain Water

Receives an array of non-negative integers representing an elevation map with unit-width bars, and returns the total volume of rainwater trapped between them after it rains. It solves this with bottom-up dynamic programming over two auxiliary arrays: leftMax[i] and rightMax[i] record the tallest bar seen so far scanning from the left and from the right respectively. The water level standing at each index is capped by its shorter bounding wall — min(leftMax[i], rightMax[i]) — minus the bar's own height there; summing that quantity across every index gives the total. Returns that single integer, the total trapped volume; an empty array returns 0.

Hard Dynamic Programming New

Four Sum

Receives an array of integers and a target value, and returns every unique quadruplet of values from the array that adds up to the target. It first sorts the array, then fixes the first two elements with nested loops (i, j) and searches the remaining range with two pointers moving inward from both ends: if the four-value sum is too small the left pointer advances, if too large the right pointer retreats, and if it matches the quadruplet is recorded before both pointers skip past any duplicate values. Each of the four loop levels (i, j, left, right) also skips over a value equal to its predecessor at the same level, which is what keeps the result free of duplicate quadruplets even when the input has repeated numbers. Returns a new array of four-value arrays in the order they were found; returns an empty array when no quadruplet sums to the target.

Medium Searching New

Number of Islands

Receives a rectangular grid of integers, 0 for water and 1 for land, and returns how many islands it contains. An island is a maximal group of land cells connected horizontally or vertically, surrounded by water (the grid's four edges are treated as bordered by water). It scans the grid in row-major order and, whenever it finds an unvisited land cell, counts a new island and floods outward from it with a depth-first search that marks every land cell reachable through its four orthogonal neighbors as visited, so the outer scan never counts the same island twice. Returns the total number of islands found; an all-water grid returns 0.

Medium Matrices New

Merge Intervals

Receives a list of [start, end] integer intervals, in any order, and returns the minimal set of non-overlapping intervals covering exactly the same points, sorted by start. It first copies and sorts the intervals by their start value — which guarantees that any interval overlapping something already emitted must overlap the most recent one — and then walks the sorted list once, keeping the last emitted range open: an interval whose start falls at or before that range's end is absorbed into it (extending its end only when it reaches further), while an interval that starts after it opens a new range. Touching intervals such as [1, 3] and [3, 5] count as overlapping. Returns the merged intervals as a new list, never mutating the caller's array; an empty input returns an empty list.

Medium Sorting New

Product of Array Except Self

Receives an array of integers and returns a new array of the same length where every position holds the product of all the other elements — never its own. It avoids division entirely (so a zero anywhere in the input needs no special case) by building two auxiliary arrays: a left-to-right pass fills prefix[i] with the product of everything strictly left of i, and a right-to-left pass fills suffix[i] with the product of everything strictly right of i, both seeded with 1 because the empty product is 1. A final pass multiplies the two per index, since everything except element i is exactly everything to its left times everything to its right. It runs in linear time; the caller's array is never mutated, an empty input returns an empty array, and a single element returns [1].

Medium General New

Longest Substring Without Repeating Characters

Receives a string of text and returns the length of the longest run of consecutive characters that contains no repetition. It uses the sliding-window technique: a window [start..i] is kept over the text so that it never holds a repeated character, while a map remembers the last index at which each character was seen. The right edge advances one character at a time; when that character was already seen inside the current window, the left edge jumps to just past that previous occurrence, discarding the repeat in a single move instead of stepping back one position at a time. After every move the window's length is compared against the best length seen so far. The whole text is scanned once, in O(n) time, using extra space proportional to the number of distinct characters. Comparison is exact and case-sensitive; spaces and punctuation count as ordinary characters. Returns the length (a number) of the longest repetition-free substring, and 0 for an empty text.

Medium Text New

Course Schedule (Topological Sort)

Given a set of N courses and the prerequisites between them, works out an order in which every course can be taken — the topological sort behind build systems, package installers and task pipelines. Receives the prerequisites as a square adjacency matrix, where a nonzero value at row i, column j means course i must be taken before course j (0 means no dependency). Applies Kahn's algorithm: it counts how many prerequisites each course is still waiting on (its indegree), queues every course that has none, and then repeatedly takes a course out of the queue, appends it to the order and decrements the indegree of every course that depended on it, queueing any that drop to zero. Returns a valid order of all N courses, or an empty list when a cycle of mutual prerequisites makes the schedule impossible.

Medium Graphs New