Skip to content
Skilled.dev

Interactive tools

Algorithm flashcards with browser-local spaced review

Recall algorithm invariants and constraints across twelve review cards, reveal worked explanations, and keep a simple review schedule in your browser.

Published · 4 min read

Recall an approach, then check your explanation

Review records stay in this browser. No account or notification permission is needed.

Loading local review schedule…

Browse the complete card deck

Count every contiguous subarray whose sum is K. Values may be positive, negative, or zero. Which approach gives expected O(n) time with a hash map?

If the current prefix is S, each earlier prefix S − K identifies one valid start. Count matches before inserting S so an empty interval is not counted. Seed the map with prefix zero once.

Trace [0, 0] with K = 0. Why must a prefix map store frequencies rather than a set?

Find two distinct positions in an already sorted numeric array that sum to a target. Return any pair, use O(1) auxiliary space, and aim for O(n) time.

If the sum is too small, the current left value cannot pair successfully with any remaining value at or below the current right endpoint. Discard it. Use the symmetric argument when the sum is too large.

Explain why a sum that is too small lets you discard the current left value.

A predicate over indexes 0 through n − 1 is false for a prefix and true thereafter. One predicate call costs O(1). Find the first true index, returning n if none is true.

A true midpoint keeps the first true index at or to its left; a false midpoint rules out everything through that midpoint. A half-open interval shrinks until its endpoints meet, including at the n sentinel.

Trace n = 0, an all-false input, and a first true value at index zero.

A directed graph may contain cycles. Every edge counts as one hop. Find a path with the fewest hops from a start vertex to a target.

BFS discovers vertices in increasing hop distance. Mark a vertex when enqueuing it, record its parent, and reconstruct the route after reaching the target. The guarantee relies on equal edge costs.

Give a graph where DFS first discovers a longer route than BFS. What changes if edge weights differ?

For each temperature in an array, report how many positions until the next strictly warmer temperature, or zero if none exists. Aim for O(n) total time.

When a warmer value arrives, resolve and pop every smaller temperature at the top. Those indexes have found their first warmer value. Each index is pushed once and popped at most once, giving linear total stack work.

For [70, 70, 71], which indexes should be resolved by the second 70?

Values arrive in a stream of unknown length. After each value, retain the K largest values seen, including duplicates. K is much smaller than the stream. Use O(K) storage and O(log K) heap comparison work per update for K ≥ 2.

The root is the weakest retained candidate. Fill the heap, then replace the root only when an incoming value is larger. Sifting repairs the heap in logarithmic time; the retained array need not be sorted.

Why is the root of this heap the smallest retained value rather than the largest?

Generate every subset of n distinct values. Each output must be an independent array. Which method directly models the include-or-skip decisions?

Every sequence of n binary decisions maps to one subset. Undo a chosen value after returning from its branch, and copy completed paths so later mutations do not alter earlier outputs. Copying all subsets costs Θ(n·2ⁿ) total output work for n ≥ 1.

Why does saving the same mutable path object break the result? What is the output-size lower bound?

Choose values from a line to maximize their sum, with no two chosen positions adjacent. Choosing nothing is allowed, and values may be negative. Return only the best sum.

For the current value, compare skipping it with taking it plus the best answer ending before its neighbor. Two running states suffice. Initial zero states allow an empty selection and keep an all-negative answer at zero.

Test [4, 5, 4] against choosing the largest available value greedily. What should an all-negative array return?

Find the longest contiguous substring with no repeated Unicode code point. Aim for expected O(n) time, where n is the number of code points.

Each rightward extension introduces at most one repeated code point. Removing leftmost code points can restore uniqueness. Both pointers move forward at most n times. In JavaScript, iterate code points deliberately; user-perceived grapheme clusters need a separate definition.

Trace abba. Can removing a leftmost character introduce a repeated character into a valid window?

An array never changes after construction. Answer many sum queries over half-open index ranges [left, right). Spend O(n) preprocessing to make each query O(1).

The two prefixes contain the same contribution before left; subtraction removes it. A leading zero also handles ranges starting at zero and empty ranges. The static-input assumption avoids costly prefix repairs after updates.

What should a query for [3, 3) return? How does a point update affect later prefix values?

In a sorted numeric array with duplicates, find the first position whose value is at least target. Return the length if every value is smaller.

The predicate is false for smaller values and true from the lower bound onward. On equality, retain the midpoint as a possible boundary and search to its left. The length sentinel handles a missing boundary.

For [2, 2, 2, 5] and target 2, what is the answer? Why can equality not return the midpoint immediately?

Count subarrays summing to 3 in [4, −1]. A proposed algorithm discards the leftmost value as soon as its running sum exceeds 3. Which observation invalidates that algorithm?

The whole interval [4, −1] sums to 3. Dropping 4 immediately loses it. A shrinking rule needs a monotone argument; signed values break this one. Prefix differences with frequencies preserve the earlier start.

Write a tiny exhaustive subarray counter and use it to test a prefix-frequency solution.

Use these review cards to recall an algorithmic approach before reading its explanation. Each card presents a constraint-based problem from the pattern quiz. Say which data structure you would use, state the invariant, estimate its cost, and name a failure case. Then reveal the explanation and judge what you remembered.

The deck contains twelve reviewed prompts. The schedule stays in this browser, with no account or notification permission. A card marked recalled returns after one, three, seven, fourteen, and then thirty days as its review level increases. A card marked for more study returns in ten minutes and resets its level.

Attempt recall before revealing the answer

Recognizing an explanation after reading it can feel easier than reconstructing it from a blank page. Use the hidden answer to create a small retrieval task. Write a few lines, speak aloud, or trace one input before pressing Reveal explanation.

For a prefix-sum prompt, naming “hash map” is incomplete. Explain which prefix differences identify valid starts, why the map stores frequencies, and when the current prefix is inserted. For a binary-search prompt, describe the half-open interval and the returned sentinel when no true value exists.

The follow-up below each revealed explanation changes the example or asks for the invariant. Use it as a second check. If you remembered a label but could not explain its consequence, study the linked guide and choose the shorter repeat interval.

Use the schedule as a practice aid

The intervals are a simple deterministic schedule, not a model of your memory or a claim about the best schedule for every learner. They create room between successful recalls and bring a difficult prompt back sooner.

Due cards include both unseen prompts and cards whose stored review time has passed. Once all currently due cards have been graded, the page reports that no cards are due. Practice all cards remains available for an optional round without waiting for the schedule.

Time comes from your device's clock. A large clock change can affect which cards appear due. Review progress is separate from course completion and is not synchronized to an account. Clearing browser storage, using another browser profile, or moving to a different device creates a separate schedule.

Grade the explanation you produced

Choose Recalled it when your attempted explanation covered the stated constraints. A solution that works only after removing a required space bound does not satisfy the same prompt. Neither does a sliding-window argument that assumes nonnegative values when negatives are allowed.

Choose Study again when the invariant was missing, a counterexample broke the approach, or you needed the answer before making a meaningful attempt. The point is to choose the next practice time, so an inflated self-grade only makes the schedule less useful.

After revealing an answer, follow its guide and implement the key operation in your preferred language. For a queue-based BFS, that includes marking at discovery and retaining the required parent or distance information. For a heap prompt, state the heap orientation and the interpretation of its root before adding an element.

Mix recognition with implementation

A flashcard deck cannot verify that you can write and debug the code. Alternate review sessions with blank-editor attempts, tests, and explanation practice. A remembered pattern name is useful only when you can connect it to the actual contract.

The pattern quiz gives multiple-choice recognition practice and explains alternatives. The edge-case practice challenges assumptions in plausible implementations. The interview rehearsal combines clarification, coding, tests, and self-review under an explicit time budget.

Use a card's linked guide to revisit a weak point, then add a personal follow-up in your own notes. For example, compare an unweighted shortest-path problem with a weighted version, or explain why deletion changes a union-find task. Those variations check whether you understand when an approach stops applying.

Understand what is saved

The browser stores only each card's identifier, review level, and next due timestamp. It does not store a transcript of your explanation, code, quiz choices, or a profile of your ability. If local storage is unavailable, the page reports that the current session will not persist.

The schedule details let you inspect next-review dates and clear the stored records. Clearing returns the deck to its initial state and does not change course progress. There is no hidden notification service or background reminder; return to this page when you want another session.

The complete card deck is also available in an expandable section. Its questions, explanations, and follow-ups are part of the public page, so a reader can use the material without maintaining a schedule. For a broader sequence, use the study-plan builder and reserve some sessions for revisiting earlier work. Keep one concrete next action for a missed card, such as tracing a failing example or rewriting the boundary loop, so review leads back to practice.