Section 07 · Stage 2: Master DSA
Coding Challenges
Coding problems for every topic taught in Stage 2, in the same order and graded easy, medium and hard, with test cases, step-by-step hints and model solutions.
What you will be able to do
- Solve easy, medium and hard problems on every Stage 2 topic on your own
- Read judge-style input and print exactly the expected output in Java
- Check your code against edge cases and large values
- Use hints to get unstuck and learn from model solutions and common mistakes
What you will learn
7.1Array & String Challenges12 lessons
Scanning arrays, counting, building strings and matrices. Practice for 5.4 Array & String Techniques.
- Second highest score20 min
- Compress the attendance code20 min
- Longest passing streak20 min
- Rotate the leaderboard by k30 min
- Spiral order of a seating plan30 min
- Best single-trade profit30 min
- Valid anagram usernames30 min
- Longest common prefix of codes30 min
- Majority vote winner30 min
- Best circular route profit45 min
- First missing positive roll number45 min
- Fewest swaps to group present days45 min
7.2Two Pointer Challenges12 lessons
Pairs, merging and in-place changes with two indexes. Practice for 5.5 Two Pointers.
- Two prices that fit the budget20 min
- Merge two sorted rank lists20 min
- Remove duplicate roll numbers in place20 min
- Three colleagues and one budget30 min
- Sort the 0-1-2 colour codes30 min
- Most water between two walls30 min
- Palindrome after one deletion30 min
- Squares of sorted temperatures30 min
- Fewest boats for all passengers30 min
- Four numbers that hit the target45 min
- Rain water trapped between buildings45 min
- Closest three-sum to a budget45 min
7.3Sliding Window Challenges12 lessons
Fixed and variable windows over subarrays and substrings. Practice for 5.6 Sliding Window.
- Average of every k-day window20 min
- Most vowels in any k-letter window20 min
- Count windows with total at least t20 min
- Best k-day sales30 min
- Shortest stretch to reach the target30 min
- Longest unique username30 min
- Anagram windows in a message30 min
- Longest stretch with at most k late days30 min
- Longest basket with two kinds of fruit30 min
- Peak server load in every window45 min
- Smallest window with all required letters45 min
- Subarrays with exactly k distinct values45 min
7.4Prefix Sum & Hashing Challenges12 lessons
Running totals, maps and sets for range and subarray questions. Practice for 5.7 Prefix Sums & Hashing.
- Range totals of daily sales20 min
- First repeated ticket ID20 min
- Two IDs that add up to a target20 min
- Subarrays with exactly k total30 min
- Group anagram tags30 min
- Longest balanced attendance stretch30 min
- Longest run of consecutive roll numbers30 min
- Seat bookings after range updates30 min
- Subarrays divisible by k30 min
- Submatrix totals of a pixel grid45 min
- Subarrays with XOR equal to k45 min
- Longest stretch with equal 0s, 1s and 2s45 min
7.5Binary Search Challenges12 lessons
Searching sorted data and searching the answer space. Practice for 5.8 Binary Search.
- Find a roll number in a sorted list20 min
- Insert position in a sorted list20 min
- Square root rounded down20 min
- First and last attempt with a score30 min
- Lowest price in a rotated list30 min
- Peak of a mountain of views30 min
- Search a sorted marks table30 min
- Search in a rotated list30 min
- Count scores below a value30 min
- Minimum truck capacity45 min
- Split chapters among k students45 min
- Median of two sorted lists45 min
7.6Recursion Challenges9 lessons
Recursive thinking on numbers, strings and paths. Practice for 5.9 Recursion in Depth.
7.7Backtracking Challenges9 lessons
Generating and searching with choose, explore and undo. Practice for 5.10 Backtracking.
7.8Bit Manipulation & Math Challenges9 lessons
Bit tricks, primes, GCD and modular arithmetic. Practice for 5.11 Bit Manipulation & Math Basics.
7.9Mixed Pattern Challenges12 lessons
Unlabelled problems from every Section 05 pattern: choosing the pattern is the task. Practice for 5.12 Pattern Practice.
- Pairs with a given difference30 min
- Longest name with at most k distinct letters30 min
- Product of all except self30 min
- Pairs with a sum divisible by k30 min
- Slowest eating speed that still finishes30 min
- Next permutation of a code30 min
- Minimum days to make bouquets45 min
- Longest repeat after k replacements45 min
- Subarrays with a bounded maximum45 min
- Smallest divisor within a threshold45 min
- Shortest part to remove to sort45 min
- Most points from cards at both ends45 min
7.10Linked List Challenges9 lessons
Pointer problems on singly and doubly linked lists. Practice for 6.1 Linked Lists.
7.11Stack & Queue Challenges9 lessons
Brackets, expressions, queues and monotonic stacks. Practice for 6.2 Stacks & Queues.
7.12Hash Table Challenges3 lessons
Building and using your own hash map. Practice for 6.3 Hash Tables from Scratch.
7.13Sorting Challenges9 lessons
Custom orders, merge sort ideas and selection. Practice for 6.4 Sorting Algorithms.
- Sort students by marks, then name20 min
- Relative order of subjects20 min
- Sort letters by frequency20 min
- Count inversions in two rankings30 min
- Largest number from digits30 min
- Minimum swaps to sort30 min
- Wiggle order of heights45 min
- Largest gap between sorted scores45 min
- Sort a linked list of marks45 min
7.14Binary Tree Challenges12 lessons
Reading trees from input, traversals, heights and paths. Practice for 6.5 Binary Trees.
- Height of a family tree20 min
- Sum of leaf values20 min
- Mirror check of a tree20 min
- Level order of an org chart30 min
- Right side view30 min
- Root-to-leaf path with a target sum30 min
- Diameter of a tree30 min
- Lowest common manager30 min
- Zigzag level order30 min
- Maximum path sum45 min
- Build a tree from two traversals45 min
- Save and restore a tree45 min
7.15BST Challenges9 lessons
Searching, validating and ordering with the BST rule. Practice for 6.6 Binary Search Trees.
7.16Heap & Trie Challenges9 lessons
Top-k, merging and medians with heaps; prefixes with tries. Practice for 6.7 Heaps & Tries.
7.17Graph Traversal Challenges12 lessons
Building graphs from input and exploring them with BFS and DFS. Practice for 6.8 Graphs: Basics & Traversal.
- Count friend groups20 min
- Flood fill a picture20 min
- Is there a path between two cities?20 min
- Number of islands30 min
- Shortest moves in a maze30 min
- Split into two teams30 min
- Cycle in a road network30 min
- Capture surrounded regions30 min
- Copy a social network30 min
- Distinct island shapes45 min
- Distance from every room to a gate45 min
- Fewest knight moves45 min
7.18Graph Algorithm Challenges9 lessons
Shortest paths, ordering tasks and grouping with union-find. Practice for 6.9 Graph Algorithms.
7.19Advanced Graph Challenges3 lessons
Negative weights, all-pairs distances and critical links. Practice for 6.10 Advanced Graph Algorithms.
7.20Greedy & Interval Challenges9 lessons
Safe local choices and interval problems. Practice for 6.11 Greedy Algorithms & Intervals.
7.211D DP Challenges12 lessons
One-dimensional states: stairs, robbers, coins and sequences. Practice for 6.12 Dynamic Programming: 1D.
- Ways to climb stairs20 min
- Cheapest way up the stairs20 min
- Nth tribonacci number20 min
- Rob houses without alarms30 min
- Fewest coins for an amount30 min
- Ways to decode a message30 min
- Ways to make change30 min
- Break a sentence into words30 min
- Largest product of a stretch30 min
- Longest increasing scores45 min
- Stock trading with a cooldown45 min
- Fewest jumps to the end45 min
7.222D DP Challenges9 lessons
Grids, knapsack and string DP. Practice for 6.13 Dynamic Programming: 2D & Common Families.
7.23Advanced DP Challenges3 lessons
Interval, bitmask and tree DP. Practice for 6.14 Advanced Dynamic Programming.
7.24String Algorithm Challenges3 lessons
Fast pattern matching and palindromes. Practice for 6.15 String Algorithms.
7.25Advanced Data Structure Challenges3 lessons
Range queries with updates and designing structures. Practice for 6.16 Advanced Data Structures.
7.26Mixed DSA Challenges12 lessons
Unlabelled problems from every Section 06 topic: choosing the structure is the task. Practice for 6.17 DSA Problem Sets.
- LRU cache operations30 min
- Browser history with back and forward30 min
- Sort a nearly sorted list30 min
- Merge accounts by shared email30 min
- Longest rising path in a height map30 min
- Vertical order of a tree30 min
- Longest valid brackets45 min
- Smallest range covering k lists45 min
- Islands after each new piece of land45 min
- Bus routes with fewest changes45 min
- Pattern matching with dot and star45 min
- Median of every window45 min
