
Add Binary
You receive two binary strings, a and b, and must return their sum as another binary string. The inputs contain only '0' and '1', have lengths from 1 to…
View solutionArticles whose authoritative difficulty is beginner.
Tagged articles
30 articles in this tag.

You receive two binary strings, a and b, and must return their sum as another binary string. The inputs contain only '0' and '1', have lengths from 1 to…
View solution
A reliable Balanced Binary Tree solution carries two facts upward from every subtree: its height and whether it is balanced.
View solution
The difficult part of inorder traversal is not remembering “left, node, right.” It is preserving the parent node while the left subtree is still…
View solution
The reliable way to solve Climbing Stairs is to stop guessing “Fibonacci” and ask one structural question: what could the final move have been?
View solution
Choosing the first or last value as the root preserves sorted order, but it produces a one-sided chain. The key is to choose a root that splits the…
View solution
The code is short. The contract is precise: test every legal starting position, require a complete match, and return as soon as the earliest one succeeds.
View solution
The code is short. The trap is assuming the rules are short enough for a pile of special cases.
View solution
The final character may be a space, so the right edge of the string is not necessarily part of the answer. The clean Length of Last Word solution is a…
View solution
Backtracking becomes much easier when you can name what one recursive call means. Here, each call assigns one phone-keypad digit, and each complete path…
View solution
The trap is to compare whole strings before identifying the stopping condition. The answer ends at the first column where agreement breaks—or when the…
View solution
The cleanest way to solve this problem is to stop counting depth globally. Ask each subtree for its answer, then let the parent combine those answers.
View solution
A left-to-right merge can overwrite values in nums1 before you have compared them. The reliable Merge Sorted Array solution uses backward two pointers:…
View solution
The common failure mode here is treating linked lists like arrays: copy the values, sort them, and rebuild. That throws away the structure the problem…
View solution
The shortest path counts only when it reaches a leaf. That one condition is what breaks the tempting min(left, right) solution.
View solution
A full reverse is easy to write. The interview-level move is to stop reversing when the two halves meet.
View solution
The requested output is one row, not the entire triangle. Build that row with one working list, and update it from right to left so each calculation still…
View solution
The output looks like mathematics. The interview task is simpler: build each row from the row you already have.
View solution
A matching sum at an internal node is not enough. The path must start at the root, end at a leaf, and satisfy the target at that boundary.
View solution
Adding one looks trivial until the last digit is 9. Then the problem becomes a compact state-tracking exercise: start where arithmetic begins, propagate a…
View solution
The word “remove” is misleading here. You do not need to shrink the Python list or delete values from its tail. You need to compact the distinct values…
View solution
When a problem says “remove duplicates,” the first instinct is often to reach for a set. That works for an unsorted list, but it misses the key clue here:…
View solution
The array is not shortened. The judge inspects only a prefix, so the job is to compact the values you keep into that prefix and return its length.
View solution
Adding every Roman symbol works for LVIII, but it turns IV into 6. The reliable Roman to Integer solution is a left-to-right scan with one local question:…
View solution
A tree comparison fails the moment you forget that a missing child is also part of the structure.
View solution
This problem asks for more. If the target is absent, return the index where it could be inserted while keeping the array sorted.
View solution
The fastest way to solve this problem is to stop searching for a square root and search for the last integer that is still feasible.
View solution
The recursive code for subsets is short. The reasoning behind it is the part worth learning: every input element creates one independent choice—include it…
View solution
The key to the Symmetric Tree solution is to compare two nodes as a mirror pair, not to traverse the left and right subtrees independently.
View solution
A strong Two Sum solution replaces repeated pair scanning with one sharper question: has the array already shown us the value this number needs?
View solution
Counting brackets tells you how many openings and closings exist. A stack tells you whether they close in the only order that nesting allows.
View solution