Code Explainers

Code explainers tagged #arrays

java
public class SortedListMerger {
 
    public static int[] merge(int[] a, int[] b) {
        int[] result = new int[a.length + b.length];

Merging two sorted arrays in Java

two-pointers merging arrays
Beginner 6 steps
javascript
// Sliding window maximum using a monotonic decreasing deque.
// Returns an array of the maximum value within each window of size k.
function maxSlidingWindow(nums, k) {
  const result = [];

Sliding window maximum with a deque

sliding-window monotonic-deque amortized-analysis
Advanced 7 steps
java
import java.util.Arrays;
 
public class SlidingWindow {
    // Returns the maximum sum of any contiguous subarray of length k.

The sliding window technique in Java

sliding-window arrays algorithms
Intermediate 8 steps
python
def two_sum_sorted(numbers, target):
    """Find indices of two values that sum to target in a sorted array."""
    left, right = 0, len(numbers) - 1
    while left < right:

Two-pointer search on sorted arrays

two-pointers arrays sorting
Intermediate 9 steps
javascript
function flatten(arr) {
  const result = [];
  for (const item of arr) {
    if (Array.isArray(item)) {

Flattening nested arrays with recursion

recursion arrays reduce
Intermediate 7 steps