CSES Problem Set Solutions
Table of contents for CSES problem set solutions
CSES Problem Set Solutions
CSES Problem Set
Introductory Problems
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Weird Algorithm | Solved |
| 2 | Missing Number | Solved |
| 3 | Repetitions | Solved |
| 4 | Increasing Array | Solved |
| 5 | Permutations | - |
| 6 | Number Spiral | - |
| 7 | Two Knights | - |
| 8 | Two Sets | - |
| 9 | Bit Strings | - |
| 10 | Trailing Zeros | - |
| 11 | Coin Piles | - |
| 12 | Palindrome Reorder | - |
| 13 | Gray Code | - |
| 14 | Tower of Hanoi | - |
| 15 | Creating Strings | - |
| 16 | Apple Division | - |
| 17 | Chessboard and Queens | - |
| 18 | Raab Game I | - |
| 19 | Mex Grid Construction | - |
| 20 | Knight Moves Grid | - |
| 21 | Grid Coloring I | - |
| 22 | Digit Queries | - |
| 23 | String Reorder | - |
| 24 | Grid Path Description | - |
Sorting and Searching
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Distinct Numbers | - |
| 2 | Apartments | - |
| 3 | Ferris Wheel | - |
| 4 | Concert Tickets | - |
| 5 | Restaurant Customers | - |
| 6 | Movie Festival | - |
| 7 | Sum of Two Values | - |
| 8 | Maximum Subarray Sum | - |
| 9 | Stick Lengths | - |
| 10 | Missing Coin Sum | - |
| 11 | Collecting Numbers | - |
| 12 | Collecting Numbers II | - |
| 13 | Playlist | - |
| 14 | Towers | - |
| 15 | Traffic Lights | - |
| 16 | Distinct Values Subarrays | - |
| 17 | Distinct Values Subsequences | - |
| 18 | Josephus Problem I | - |
| 19 | Josephus Problem II | - |
| 20 | Nested Ranges Check | - |
| 21 | Nested Ranges Count | - |
| 22 | Room Allocation | - |
| 23 | Factory Machines | - |
| 24 | Tasks and Deadlines | - |
| 25 | Reading Books | - |
| 26 | Sum of Three Values | - |
| 27 | Sum of Four Values | - |
| 28 | Nearest Smaller Values | - |
| 29 | Subarray Sums I | - |
| 30 | Subarray Sums II | - |
| 31 | Subarray Divisibility | - |
| 32 | Distinct Values Subarrays II | - |
| 33 | Array Division | - |
| 34 | Movie Festival II | - |
| 35 | Maximum Subarray Sum II | - |
Dynamic Programming
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Dice Combinations | - |
| 2 | Minimizing Coins | - |
| 3 | Coin Combinations I | - |
| 4 | Coin Combinations II | - |
| 5 | Removing Digits | - |
| 6 | Grid Paths I | - |
| 7 | Book Shop | - |
| 8 | Array Description | - |
| 9 | Counting Towers | - |
| 10 | Edit Distance | - |
| 11 | Longest Common Subsequence | - |
| 12 | Rectangle Cutting | - |
| 13 | Minimal Grid Path | - |
| 14 | Money Sums | - |
| 15 | Removal Game | - |
| 16 | Two Sets II | - |
| 17 | Mountain Range | - |
| 18 | Increasing Subsequence | - |
| 19 | Projects | - |
| 20 | Elevator Rides | - |
| 21 | Counting Tilings | - |
| 22 | Counting Numbers | - |
| 23 | Increasing Subsequence II | - |
Graph Algorithms
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Counting Rooms | - |
| 2 | Labyrinth | - |
| 3 | Building Roads | - |
| 4 | Message Route | - |
| 5 | Building Teams | - |
| 6 | Round Trip | - |
| 7 | Monsters | - |
| 8 | Shortest Routes I | - |
| 9 | Shortest Routes II | - |
| 10 | High Score | - |
| 11 | Flight Discount | - |
| 12 | Cycle Finding | - |
| 13 | Flight Routes | - |
| 14 | Round Trip II | - |
| 15 | Course Schedule | - |
| 16 | Longest Flight Route | - |
| 17 | Game Routes | - |
| 18 | Investigation | - |
| 19 | Planets Queries I | - |
| 20 | Planets Queries II | - |
| 21 | Planets Cycles | - |
| 22 | Road Reparation | - |
| 23 | Road Construction | - |
| 24 | Flight Routes Check | - |
| 25 | Planets and Kingdoms | - |
| 26 | Giant Pizza | - |
| 27 | Coin Collector | - |
| 28 | Mail Delivery | - |
| 29 | De Bruijn Sequence | - |
| 30 | Teleporters Path | - |
| 31 | Hamiltonian Flights | - |
| 32 | Knight’s Tour | - |
| 33 | Download Speed | - |
| 34 | Police Chase | - |
| 35 | School Dance | - |
| 36 | Distinct Routes | - |
Range Queries
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Static Range Sum Queries | - |
| 2 | Static Range Minimum Queries | - |
| 3 | Dynamic Range Sum Queries | - |
| 4 | Dynamic Range Minimum Queries | - |
| 5 | Range Xor Queries | - |
| 6 | Range Update Queries | - |
| 7 | Forest Queries | - |
| 8 | Hotel Queries | - |
| 9 | List Removals | - |
| 10 | Salary Queries | - |
| 11 | Prefix Sum Queries | - |
| 12 | Pizzeria Queries | - |
| 13 | Visible Buildings Queries | - |
| 14 | Range Interval Queries | - |
| 15 | Subarray Sum Queries | - |
| 16 | Subarray Sum Queries II | - |
| 17 | Distinct Values Queries | - |
| 18 | Distinct Values Queries II | - |
| 19 | Increasing Array Queries | - |
| 20 | Movie Festival Queries | - |
| 21 | Forest Queries II | - |
| 22 | Range Updates and Sums | - |
| 23 | Polynomial Queries | - |
| 24 | Range Queries and Copies | - |
| 25 | Missing Coin Sum Queries | - |
Tree Algorithms
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Subordinates | - |
| 2 | Tree Matching | - |
| 3 | Tree Diameter | - |
| 4 | Tree Distances I | - |
| 5 | Tree Distances II | - |
| 6 | Company Queries I | - |
| 7 | Company Queries II | - |
| 8 | Distance Queries | - |
| 9 | Counting Paths | - |
| 10 | Subtree Queries | - |
| 11 | Path Queries | - |
| 12 | Path Queries II | - |
| 13 | Distinct Colors | - |
| 14 | Finding a Centroid | - |
| 15 | Fixed-Length Paths I | - |
| 16 | Fixed-Length Paths II | - |
Mathematics
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Josephus Queries | - |
| 2 | Exponentiation | - |
| 3 | Exponentiation II | - |
| 4 | Counting Divisors | - |
| 5 | Common Divisors | - |
| 6 | Sum of Divisors | - |
| 7 | Divisor Analysis | - |
| 8 | Prime Multiples | - |
| 9 | Counting Coprime Pairs | - |
| 10 | Next Prime | - |
| 11 | Binomial Coefficients | - |
| 12 | Creating Strings II | - |
| 13 | Distributing Apples | - |
| 14 | Christmas Party | - |
| 15 | Permutation Order | - |
| 16 | Permutation Rounds | - |
| 17 | Bracket Sequences I | - |
| 18 | Bracket Sequences II | - |
| 19 | Counting Necklaces | - |
| 20 | Counting Grids | - |
| 21 | Fibonacci Numbers | - |
| 22 | Throwing Dice | - |
| 23 | Graph Paths I | - |
| 24 | Graph Paths II | - |
| 25 | System of Linear Equations | - |
| 26 | Sum of Four Squares | - |
| 27 | Triangle Number Sums | - |
| 28 | Dice Probability | - |
| 29 | Moving Robots | - |
| 30 | Candy Lottery | - |
| 31 | Inversion Probability | - |
| 32 | Stick Game | - |
| 33 | Nim Game I | - |
| 34 | Nim Game II | - |
| 35 | Stair Game | - |
| 36 | Grundy’s Game | - |
| 37 | Another Game | - |
String Algorithms
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Word Combinations | - |
| 2 | String Matching | - |
| 3 | Finding Borders | - |
| 4 | Finding Periods | - |
| 5 | Minimal Rotation | - |
| 6 | Longest Palindrome | - |
| 7 | All Palindromes | - |
| 8 | Required Substring | - |
| 9 | Palindrome Queries | - |
| 10 | Finding Patterns | - |
| 11 | Counting Patterns | - |
| 12 | Pattern Positions | - |
| 13 | Distinct Substrings | - |
| 14 | Distinct Subsequences | - |
| 15 | Repeating Substring | - |
| 16 | String Functions | - |
| 17 | Inverse Suffix Array | - |
| 18 | String Transform | - |
| 19 | Substring Order I | - |
| 20 | Substring Order II | - |
| 21 | Substring Distribution | - |
Geometry
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Point Location Test | - |
| 2 | Line Segment Intersection | - |
| 3 | Polygon Area | - |
| 4 | Point in Polygon | - |
| 5 | Polygon Lattice Points | - |
| 6 | Minimum Euclidean Distance | - |
| 7 | Convex Hull | - |
| 8 | Maximum Manhattan Distances | - |
| 9 | All Manhattan Distances | - |
| 10 | Intersection Points | - |
| 11 | Line Segments Trace I | - |
| 12 | Line Segments Trace II | - |
| 13 | Lines and Queries I | - |
| 14 | Lines and Queries II | - |
| 15 | Area of Rectangles | - |
| 16 | Robot Path | - |
Advanced Techniques
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Meet in the Middle | - |
| 2 | Hamming Distance | - |
| 3 | Corner Subgrid Check | - |
| 4 | Corner Subgrid Count | - |
| 5 | Reachable Nodes | - |
| 6 | Reachability Queries | - |
| 7 | Cut and Paste | - |
| 8 | Substring Reversals | - |
| 9 | Reversals and Sums | - |
| 10 | Necessary Roads | - |
| 11 | Necessary Cities | - |
| 12 | Eulerian Subgraphs | - |
| 13 | Monster Game I | - |
| 14 | Monster Game II | - |
| 15 | Subarray Squares | - |
| 16 | Houses and Schools | - |
| 17 | Knuth Division | - |
| 18 | Apples and Bananas | - |
| 19 | One Bit Positions | - |
| 20 | Signal Processing | - |
| 21 | New Roads Queries | - |
| 22 | Dynamic Connectivity | - |
| 23 | Parcel Delivery | - |
| 24 | Task Assignment | - |
| 25 | Distinct Routes II | - |
Sliding Window Problems
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Sliding Window Sum | - |
| 2 | Sliding Window Minimum | - |
| 3 | Sliding Window Xor | - |
| 4 | Sliding Window Or | - |
| 5 | Sliding Window Distinct Values | - |
| 6 | Sliding Window Mode | - |
| 7 | Sliding Window Mex | - |
| 8 | Sliding Window Median | - |
| 9 | Sliding Window Cost | - |
| 10 | Sliding Window Inversions | - |
| 11 | Sliding Window Advertisement | - |
Interactive Problems
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Hidden Integer | - |
| 2 | Hidden Permutation | - |
| 3 | K-th Highest Score | - |
| 4 | Permuted Binary Strings | - |
| 5 | Colored Chairs | - |
| 6 | Inversion Sorting | - |
Bitwise Operations
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Counting Bits | - |
| 2 | Maximum Xor Subarray | - |
| 3 | Maximum Xor Subset | - |
| 4 | Number of Subset Xors | - |
| 5 | K Subset Xors | - |
| 6 | All Subarray Xors | - |
| 7 | Xor Pyramid Peak | - |
| 8 | Xor Pyramid Diagonal | - |
| 9 | Xor Pyramid Row | - |
| 10 | SOS Bit Problem | - |
| 11 | And Subset Count | - |
Construction Problems
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Inverse Inversions | - |
| 2 | Monotone Subsequences | - |
| 3 | Third Permutation | - |
| 4 | Permutation Prime Sums | - |
| 5 | Chess Tournament | - |
| 6 | Distinct Sums Grid | - |
| 7 | Filling Trominos | - |
| 8 | Grid Path Construction | - |
Advanced Graph Problems
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Nearest Shops | - |
| 2 | Prüfer Code | - |
| 3 | Tree Traversals | - |
| 4 | Course Schedule II | - |
| 5 | Acyclic Graph Edges | - |
| 6 | Strongly Connected Edges | - |
| 7 | Even Outdegree Edges | - |
| 8 | Graph Girth | - |
| 9 | Fixed Length Walk Queries | - |
| 10 | Transfer Speeds Sum | - |
| 11 | MST Edge Check | - |
| 12 | MST Edge Set Check | - |
| 13 | MST Edge Cost | - |
| 14 | Network Breakdown | - |
| 15 | Tree Coin Collecting I | - |
| 16 | Tree Coin Collecting II | - |
| 17 | Tree Isomorphism I | - |
| 18 | Tree Isomorphism II | - |
| 19 | Flight Route Requests | - |
| 20 | Critical Cities | - |
| 21 | Visiting Cities | - |
| 22 | Graph Coloring | - |
| 23 | Bus Companies | - |
| 24 | Split into Two Paths | - |
| 25 | Network Renovation | - |
| 26 | Forbidden Cities | - |
| 27 | Creating Offices | - |
| 28 | New Flight Routes | - |
Counting Problems
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Filled Subgrid Count I | - |
| 2 | Filled Subgrid Count II | - |
| 3 | All Letter Subgrid Count I | - |
| 4 | All Letter Subgrid Count II | - |
| 5 | Border Subgrid Count I | - |
| 6 | Border Subgrid Count II | - |
| 7 | Raab Game II | - |
| 8 | Empty String | - |
| 9 | Permutation Inversions | - |
| 10 | Counting Bishops | - |
| 11 | Counting Sequences | - |
| 12 | Grid Paths II | - |
| 13 | Counting Permutations | - |
| 14 | Grid Completion | - |
| 15 | Counting Reorders | - |
| 16 | Tournament Graph Distribution | - |
| 17 | Collecting Numbers Distribution | - |
| 18 | Functional Graph Distribution | - |
Additional Problems I
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Shortest Subsequence | - |
| 2 | Distinct Values Sum | - |
| 3 | Distinct Values Splits | - |
| 4 | Swap Game | - |
| 5 | Beautiful Permutation II | - |
| 6 | Multiplication Table | - |
| 7 | Bubble Sort Rounds I | - |
| 8 | Bubble Sort Rounds II | - |
| 9 | Nearest Campsites I | - |
| 10 | Nearest Campsites II | - |
| 11 | Advertisement | - |
| 12 | Special Substrings | - |
| 13 | Counting LCM Arrays | - |
| 14 | Square Subsets | - |
| 15 | Subarray Sum Constraints | - |
| 16 | Water Containers Moves | - |
| 17 | Water Containers Queries | - |
| 18 | Stack Weights | - |
| 19 | Maximum Average Subarrays | - |
| 20 | Subsets with Fixed Average | - |
| 21 | Two Array Average | - |
| 22 | Pyramid Array | - |
| 23 | Permutation Subsequence | - |
| 24 | Bit Inversions | - |
| 25 | Writing Numbers | - |
| 26 | Letter Pair Move Game | - |
| 27 | Maximum Building I | - |
| 28 | Sorting Methods | - |
| 29 | Cyclic Array | - |
| 30 | List of Sums | - |
Additional Problems II
| SL No | Problem Name | Status |
|---|---|---|
| 1 | Bouncing Ball Steps | - |
| 2 | Bouncing Ball Cycle | - |
| 3 | Knight Moves Queries | - |
| 4 | K Subset Sums I | - |
| 5 | K Subset Sums II | - |
| 6 | Increasing Array II | - |
| 7 | Food Division | - |
| 8 | Swap Round Sorting | - |
| 9 | Binary Subsequences | - |
| 10 | School Excursion | - |
| 11 | Coin Grid | - |
| 12 | Grid Coloring II | - |
| 13 | Programmers and Artists | - |
| 14 | Removing Digits II | - |
| 15 | Coin Arrangement | - |
| 16 | Replace with Difference | - |
| 17 | Grid Puzzle I | - |
| 18 | Grid Puzzle II | - |
| 19 | Bit Substrings | - |
| 20 | Reversal Sorting | - |
| 21 | Book Shop II | - |
| 22 | GCD Subsets | - |
| 23 | Minimum Cost Pairs | - |
| 24 | Same Sum Subsets | - |
| 25 | Mex Grid Queries | - |
| 26 | Maximum Building II | - |
| 27 | Stick Divisions | - |
| 28 | Stick Difference | - |
| 29 | Coding Company | - |
| 30 | Two Stacks Sorting | - |
This post is licensed under CC BY 4.0 by the author.