The CSES Problem Set contains a collection of algorithm programming practice problems. You can access the problems here: https://cses.fi/problemset/list/. This set has 400 classic problems of various categories and difficulties.
This was my practice run for ICPC. There are more than 290 accepted solutions listed here. I have also added tags for some of the problems.
- At first try to come up with a solution by yourself.
- If you can't then read some article on the associated tags and try again.
- If you still can't then you proceed to the solution. Try to understand what is going on. Then try your own approach.
Milestones:
- 29/12/2021:
Solved 100th Problem - 05/05/2022:
Solved 150th Problem - 05/12/2022:
Solved 200th Problem - 11/11/2023:
Solved 250th Problem - 14/06/2025:
Solved all Searching and Sorting Problems - 26/06/2025:
Solved all Range Queries Problems - 30/10/2025:
Solved all Introductory Problems - 07/11/2025:
Solved 300th Problem
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Weird Algorithm | Code | |
| ✔ | Missing Number | Code | |
| ✔ | Repetitions | Code | |
| ✔ | Increasing Array | Code | |
| ✔ | Permutations | Code | |
| ✔ | Number Spiral | Code | |
| ✔ | Two Knights | Code | |
| ✔ | Two Sets | Code | |
| ✔ | Bit Strings | Code | |
| ✔ | Trailing Zeros | Code | |
| ✔ | Coin Piles | Code | |
| ✔ | Palindrome Reorder | Code | |
| ✔ | Gray Code | Code | |
| ✔ | Tower of Hanoi | Code | |
| ✔ | Creating Strings | Code | |
| ✔ | Apple Division | Code | |
| ✔ | Chessboard and Queens | Code | |
| ✔ | Raab Game I | Code | |
| ✔ | Mex Grid Construction | Brute Force | Code |
| ✔ | Knight Moves Grid | BFS | Code |
| ✔ | Grid Coloring I | greedy | Code |
| ✔ | Digit Queries | Code | |
| ✔ | String Reorder | greedy constructive | Code |
| ✔ | Grid Path Description | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Distinct Numbers | Code | |
| ✔ | Apartments | Code | |
| ✔ | Ferris Wheel | Code | |
| ✔ | Concert Tickets | Code | |
| ✔ | Restaurant Customers | Code | |
| ✔ | Movie Festival | Code | |
| ✔ | Sum of Two Values | Code | |
| ✔ | Maximum Subarray Sum | Code | |
| ✔ | Stick Lengths | Code | |
| ✔ | Missing Coin Sum | Code | |
| ✔ | Collecting Numbers | Code | |
| ✔ | Collecting Numbers II | Code | |
| ✔ | Playlist | Code | |
| ✔ | Towers | Code | |
| ✔ | Traffic Lights | Code | |
| ✔ | Distinct Values Subarrays | Counting | Code |
| ✔ | Distinct Values Subsequences | Counting | Code |
| ✔ | Josephus Problem I | Code | |
| ✔ | Josephus Problem II | OST | Code |
| ✔ | Nested Ranges Check | Code | |
| ✔ | Nested Ranges Count | Point Update Range Sum | Code |
| ✔ | Room Allocation | Code | |
| ✔ | Factory Machines | Code | |
| ✔ | Tasks and Deadlines | Code | |
| ✔ | Reading Books | Code | |
| ✔ | Sum of Three Values | Code | |
| ✔ | Sum of Four Values | Code | |
| ✔ | Nearest Smaller Values | Code | |
| ✔ | Subarray Sums I | Code | |
| ✔ | Subarray Sums II | Code | |
| ✔ | Subarray Divisibility | Code | |
| ✔ | Distinct Values Subarrays II | Code | |
| ✔ | Array Division | Code | |
| ✔ | Movie Festival II | Greedy Scheduling Binary Search | Code |
| ✔ | Maximum Subarray Sum II | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Dice Combinations | Coin change DP | Code |
| ✔ | Minimizing Coins | Coin change DP | Code |
| ✔ | Coin Combinations I | Coin change DP | Code |
| ✔ | Coin Combinations II | Coin change DP | Code |
| ✔ | Removing Digits | Code | |
| ✔ | Grid Paths I | Code | |
| ✔ | Book Shop | Code | |
| ✔ | Array Description | Code | |
| ✔ | Counting Towers | Code | |
| ✔ | Edit Distance | Code | |
| ✔ | Longest Common Subsequence | LCS | Code |
| ✔ | Rectangle Cutting | Code | |
| ✔ | Minimal Grid Path | BFS | Code |
| ✔ | Money Sums | Code | |
| ✔ | Removal Game | Code | |
| ✔ | Two Sets II | Knapsack DP | Code |
| Mountain Range | Code | ||
| ✔ | Increasing Subsequence | LIS | Code |
| ✔ | Projects | Code | |
| ✔ | Elevator Rides | Bitmask DP | Code |
| ✔ | Counting Tilings | Broken Profile DP Bitmask | Code |
| ✔ | Counting Numbers | Digit Dp | Code |
| ✔ | Increasing Subsequence II | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Counting Rooms | BFS | Code |
| ✔ | Labyrinth | BFS | Code |
| ✔ | Building Roads | BFS DFS Forest Counting | Code |
| ✔ | Message Route | BFS | Code |
| ✔ | Building Teams | Bicoloring DFS | Code |
| ✔ | Round Trip | Cycle in undirected graph DFS | Code |
| ✔ | Monsters | BFS | Code |
| ✔ | Shortest Routes I | Single Source Shortest Path Dijkstra | Code |
| ✔ | Shortest Routes II | All Pair Shortes Path Floyd Warshall | Code |
| ✔ | High Score | Single Source Shortest Path Bellman Ford | Code |
| ✔ | Flight Discount | Single Source Shortest Path Dijkstra | Code |
| ✔ | Cycle Finding | Negative Cycle Bellman Ford | Code |
| ✔ | Flight Routes | Dijkstra | Code |
| ✔ | Round Trip II | DFS Cycle in directed graph | Code |
| ✔ | Course Schedule | Topological Sort | Code |
| ✔ | Longest Flight Route | Topological Sort DP | Code |
| ✔ | Game Routes | Topological Sort DP | Code |
| ✔ | Investigation | Dijkstra | Code |
| ✔ | Planets Queries I | Binary Lifting | Code |
| Planets Queries II | Code | ||
| ✔ | Planets Cycles | DFS | Code |
| ✔ | Road Reparation | Minimum Spanning Tree Kruskal | Code |
| ✔ | Road Construction | DSU | Code |
| ✔ | Flight Routes Check | Strongly Connected Components | Code |
| ✔ | Planets and Kingdoms | Strongly Connected Components | Code |
| ✔ | Giant Pizza | 2-SAT | Code |
| ✔ | Coin Collector | Condensation Graph Topological Sort DP | Code |
| ✔ | Mail Delivery | Euler Tour - Undirected | Code |
| ✔ | De Bruijn Sequence | De Bruijn Sequence | Code |
| ✔ | Teleporters Path | Euler Path - Directed | Code |
| ✔ | Hamiltonian Flights | Hamiltonian Path Bitmask DP | Code |
| ✔ | Knight's Tour | Hamiltonian Path Heuristics | Code |
| ✔ | Download Speed | Max Flow Min Cut Push Relabel Dinic | Code |
| ✔ | Police Chase | Max Flow Min Cut Push Relabel | Code |
| ✔ | School Dance | Max Flow``Bipartite Matching Hopkroft Carp | Code |
| ✔ | Distinct Routes | Max Flow Dinic Path reconstruction | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Static Range Sum Queries | Code | |
| ✔ | Static Range Minimum Queries | Code | |
| ✔ | Dynamic Range Sum Queries | Code | |
| ✔ | Dynamic Range Minimum Queries | Code | |
| ✔ | Range Xor Queries | Code | |
| ✔ | Range Update Queries | Code | |
| ✔ | Forest Queries | Code | |
| ✔ | Hotel Queries | Code | |
| ✔ | List Removals | Code | |
| ✔ | Salary Queries | Code | |
| ✔ | Prefix Sum Queries | Code | |
| ✔ | Pizzeria Queries | Code | |
| ✔ | Visible Buildings Queries | Binary Lifting | Code |
| ✔ | Range Interval Queries | Merge Sort Tree | Code |
| ✔ | Subarray Sum Queries | Code | |
| ✔ | Subarray Sum Queries II | Segment tree | Code |
| ✔ | Distinct Values Queries | Code | |
| ✔ | Distinct Values Queries II | Segment Tree | Code |
| ✔ | Increasing Array Queries | Segment tree Tree walking | Code |
| ✔ | Movie Festival Queries | Greedy Scheduling RMQ Binary Lifting | Code |
| ✔ | Forest Queries II | Code | |
| ✔ | Range Updates and Sums | Code | |
| ✔ | Polynomial Queries | Lazy Segment Tree | Code |
| ✔ | Range Queries and Copies | Persistent Segment Tree | Code |
| ✔ | Missing Coin Sum Queries | Iterative Segment Tree | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Subordinates | Subtree DP | Code |
| ✔ | Tree Matching | Tree DP | Code |
| ✔ | Tree Diameter | Tree Diameter | Code |
| ✔ | Tree Distances I | Tree Diameter | Code |
| ✔ | Tree Distances II | Tree Rerooting DP | Code |
| ✔ | Company Queries I | Binary Lifting | Code |
| ✔ | Company Queries II | LCA | Code |
| ✔ | Distance Queries | LCA | Code |
| ✔ | Counting Paths | HLD | Code |
| ✔ | Subtree Queries | HLD | Code |
| ✔ | Path Queries | HLD | Code |
| ✔ | Path Queries II | HLD | Code |
| ✔ | Distinct Colors | MO on Tree / Sack Small to Large | Code |
| ✔ | Finding a Centroid | Centroid | Code |
| ✔ | Fixed-Length Paths I | Centroid Decomposition | Code |
| Fixed-Length Paths II | Centroid Decomposition | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Josephus Queries | Code | |
| ✔ | Exponentiation | Code | |
| ✔ | Exponentiation II | Code | |
| ✔ | Counting Divisors | Code | |
| ✔ | Common Divisors | Code | |
| ✔ | Sum of Divisors | Code | |
| ✔ | Divisor Analysis | Code | |
| ✔ | Prime Multiples | Code | |
| ✔ | Counting Coprime Pairs | Code | |
| ✔ | Next Prime | Segmented Sieve | Code |
| ✔ | Binomial Coefficients | Code | |
| ✔ | Creating Strings II | Code | |
| ✔ | Distributing Apples | Code | |
| ✔ | Christmas Party | Code | |
| Permutation Order | Code | ||
| Permutation Rounds | Code | ||
| ✔ | Bracket Sequences I | Code | |
| ✔ | Bracket Sequences II | Code | |
| ✔ | Counting Necklaces | Code | |
| ✔ | Counting Grids | Code | |
| ✔ | Fibonacci Numbers | Code | |
| ✔ | Throwing Dice | Code | |
| ✔ | Graph Paths I | Code | |
| ✔ | Graph Paths II | Code | |
| System of Linear Equations | Code | ||
| Sum of Four Squares | Code | ||
| Triangle Number Sums | Code | ||
| ✔ | Dice Probability | Code | |
| Moving Robots | Code | ||
| Candy Lottery | Expected Value | Code | |
| Inversion Probability | Code | ||
| ✔ | Stick Game | Code | |
| ✔ | Nim Game I | Code | |
| ✔ | Nim Game II | Code | |
| ✔ | Stair Game | Code | |
| ✔ | Grundy's Game | Code | |
| ✔ | Another Game | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Word Combinations | Trie DP | Code |
| ✔ | String Matching | Suffix array / Hashing | Code |
| ✔ | Finding Borders | Z function Prefix function / Hashing | Code |
| ✔ | Finding Periods | Z function Prefix function / Hashing | Code |
| ✔ | Minimal Rotation | Suffix Automata | Code |
| ✔ | Longest Palindrome | Manacher | Code |
| All Palindromes | Code | ||
| Required Substring | Code | ||
| ✔ | Palindrome Queries | Range Sum Hashing | Code |
| ✔ | Finding Patterns | Code | |
| ✔ | Counting Patterns | Code | |
| ✔ | Pattern Positions | Code | |
| ✔ | Distinct Substrings | Code | |
| ✔ | Distinct Subsequences | Code | |
| ✔ | Repeating Substring | Hashing Binary Search | Code |
| ✔ | String Functions | Code | |
| Inverse Suffix Array | Code | ||
| ✔ | String Transform | Inverse Burrows Wheeler Transform | Code |
| ✔ | Substring Order I | Code | |
| ✔ | Substring Order II | Code | |
| ✔ | Substring Distribution | Suffix Array Longest Common Prefix | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Point Location Test | Cross Product | Code |
| ✔ | Line Segment Intersection | Code | |
| ✔ | Polygon Area | Code | |
| ✔ | Point in Polygon | Code | |
| ✔ | Polygon Lattice Points | Code | |
| Minimum Euclidean Distance | Code | ||
| ✔ | Convex Hull | Code | |
| ✔ | Maximum Manhattan Distances | Chebyshev Transformation | Code |
| ✔ | All Manhattan Distances | Counting | Code |
| ✔ | Intersection Points | Range Query with Sweep Line | Code |
| Line Segments Trace I | Code | ||
| Line Segments Trace II | Code | ||
| Lines and Queries I | Code | ||
| Lines and Queries II | Code | ||
| ✔ | Area of Rectangles | Range Query and Update with Sweep Line | Code |
| Robot Path | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Meet in the Middle | Code | |
| ✔ | Hamming Distance | Code | |
| Corner Subgrid Check | Code | ||
| ✔ | Corner Subgrid Count | Code | |
| ✔ | Reachable Nodes | Code | |
| ✔ | Reachability Queries | Code | |
| ✔ | Cut and Paste | Implicit Treap | Code |
| ✔ | Substring Reversals | Implicit Treap | Code |
| ✔ | Reversals and Sums | Implicit Treap | Code |
| ✔ | Necessary Roads | Bridges | Code |
| ✔ | Necessary Cities | Articulation Points | Code |
| Eulerian Subgraphs | Code | ||
| ✔ | Monster Game I | DP Convex Hull Optimization | Code |
| ✔ | Monster Game II | DP Convex Hull Optimization | Code |
| ✔ | Subarray Squares | DP Convex Hull Optimization | Code |
| Houses and Schools | Code | ||
| ✔ | Knuth Division | DP Knuth Optimization | Code |
| ✔ | Apples and Bananas | FFT | Code |
| ✔ | One Bit Positions | FFT | Code |
| ✔ | Signal Processing | FFT | Code |
| ✔ | New Roads Queries | HLD | Code |
| ✔ | Dynamic Connectivity | Dynamic DSU | Code |
| ✔ | Parcel Delivery | Max Flow Min Cost Fixed flow | Code |
| ✔ | Task Assignment | Max Flow Min Cost | Code |
| ✔ | Distinct Routes II | Max Flow Min Cost Path reconstruction | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Sliding Window Sum | Code | |
| ✔ | Sliding Window Minimum | Code | |
| ✔ | Sliding Window Xor | Code | |
| ✔ | Sliding Window Or | Two Stack | Code |
| ✔ | Sliding Window Distinct Values | Code | |
| ✔ | Sliding Window Mode | Code | |
| ✔ | Sliding Window Mex | Code | |
| ✔ | Sliding Window Median | Code | |
| ✔ | Sliding Window Cost | Code | |
| ✔ | Sliding Window Inversions | Segment Tree | Code |
| Sliding Window Advertisement | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Hidden Integer | Binary Search | Code |
| ✔ | Hidden Permutation | Merge Sort | Code |
| ✔ | K-th Highest Score | Binary Seach | Code |
| Permuted Binary Strings | Code | ||
| Colored Chairs | Code | ||
| Inversion Sorting | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Counting Bits | Code | |
| ✔ | Maximum Xor Subarray | Trie Divide and Conquer | Code |
| ✔ | Maximum Xor Subset | Xor Basis | Code |
| ✔ | Number of Subset Xors | Xor Basis | Code |
| K Subset Xors | Code | ||
| All Subarray Xors | Code | ||
| ✔ | Xor Pyramid Peak | Code | |
| Xor Pyramid Diagonal | Code | ||
| Xor Pyramid Row | Code | ||
| ✔ | SOS Bit Problem | Code | |
| And Subset Count | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Inverse Inversions | Code | |
| ✔ | Monotone Subsequences | Code | |
| ✔ | Third Permutation | Construction | Code |
| ✔ | Permutation Prime Sums | Math Greedy | Code |
| ✔ | Chess Tournament | Greedy | Code |
| Distinct Sums Grid | Code | ||
| Filling Trominos | Code | ||
| Grid Path Construction | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Nearest Shops | BFS | Code |
| ✔ | Prüfer Code | Prüfer Code | Code |
| ✔ | Tree Traversals | Code | |
| Course Schedule II | Code | ||
| ✔ | Acyclic Graph Edges | Code | |
| ✔ | Strongly Connected Edges | Bridge | Code |
| Even Outdegree Edges | Code | ||
| ✔ | Graph Girth | BFS Tree | Code |
| Fixed Length Walk Queries | Code | ||
| Transfer Speeds Sum | Code | ||
| ✔ | MST Edge Check | DSU | Code |
| MST Edge Set Check | Code | ||
| ✔ | MST Edge Cost | HLD DSU | Code |
| ✔ | Network Breakdown | DSU with rollback | Code |
| Tree Coin Collecting I | Code | ||
| Tree Coin Collecting II | Code | ||
| ✔ | Tree Isomorphism I | Tree Isomorphism rooted | Code |
| ✔ | Tree Isomorphism II | Tree Isomorphism unrooted | Code |
| Flight Route Requests | Code | ||
| ✔ | Critical Cities | Dominator Tree | Code |
| ✔ | Visiting Cities | Dijkstra Articulation Point | Code |
| Graph Coloring | Code | ||
| Bus Companies | Code | ||
| Split into Two Paths | Code | ||
| ✔ | Network Renovation | Euler Tour | Code |
| ✔ | Forbidden Cities | Block Cut Tree | Code |
| Creating Offices | Code | ||
| New Flight Routes | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Filled Subgrid Count I | DP | Code |
| ✔ | Filled Subgrid Count II | DP Monotone stack | Code |
| All Letter Subgrid Count I | Code | ||
| All Letter Subgrid Count II | Code | ||
| Border Subgrid Count I | Code | ||
| Border Subgrid Count II | Code | ||
| Raab Game II | Code | ||
| Empty String | Code | ||
| Permutation Inversions | Code | ||
| Counting Bishops | Code | ||
| ✔ | Counting Sequences | Inclusion Exclusion Principle | Code |
| ✔ | Grid Paths II | Code | |
| ✔ | Counting Permutations | Code | |
| Grid Completion | Code | ||
| Counting Reorders | Code | ||
| Tournament Graph Distribution | Code | ||
| Collecting Numbers Distribution | Code | ||
| Functional Graph Distribution | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Shortest Subsequence | Code | |
| ✔ | Distinct Values Sum | Contribution Technique | Code |
| ✔ | Distinct Values Splits | DP Prefix Sum | Code |
| ✔ | Swap Game | Code | |
| Beautiful Permutation II | Code | ||
| ✔ | Multiplication Table | Binary Search Harmonic Progression | Code |
| ✔ | Bubble Sort Rounds I | Sorting | Code |
| Bubble Sort Rounds II | Code | ||
| Nearest Campsites I | Code | ||
| Nearest Campsites II | Code | ||
| ✔ | Advertisement | Segment Tree | Code |
| ✔ | Special Substrings | Constructive Hashing | Code |
| Counting LCM Arrays | Code | ||
| Square Subsets | Code | ||
| Subarray Sum Constraints | Code | ||
| Water Containers Moves | Code | ||
| Water Containers Queries | Code | ||
| Stack Weights | Code | ||
| Maximum Average Subarrays | Code | ||
| Subsets with Fixed Average | Code | ||
| Two Array Average | Code | ||
| Pyramid Array | Code | ||
| Permutation Subsequence | Code | ||
| ✔ | Bit Inversions | Code | |
| ✔ | Writing Numbers | Code | |
| Letter Pair Move Game | Code | ||
| ✔ | Maximum Building I | Segment Tree | Code |
| Sorting Methods | Code | ||
| ✔ | Cyclic Array | Binary Search Greedy | Code |
| List of Sums | Code |
| Status | Name | Tags | Link |
|---|---|---|---|
| ✔ | Bouncing Ball Steps | Code | |
| Bouncing Ball Cycle | Code | ||
| Knight Moves Queries | Code | ||
| K Subset Sums I | Code | ||
| K Subset Sums II | Code | ||
| Increasing Array II | Code | ||
| Food Division | Code | ||
| Swap Round Sorting | Code | ||
| Binary Subsequences | Code | ||
| ✔ | School Excursion | Knapsack DP Bitset | Code |
| Coin Grid | Code | ||
| Grid Coloring II | Code | ||
| Programmers and Artists | Code | ||
| Removing Digits II | Code | ||
| Coin Arrangement | Code | ||
| Replace with Difference | Code | ||
| ✔ | Grid Puzzle I | Max Flow Min Cut | Code |
| ✔ | Grid Puzzle II | Max Flow Max Cost | Code |
| ✔ | Bit Substrings | FFT | Code |
| ✔ | Reversal Sorting | Implicit Treap | Code |
| Book Shop II | Code | ||
| GCD Subsets | Code | ||
| Minimum Cost Pairs | Code | ||
| Same Sum Subsets | Code | ||
| ✔ | Mex Grid Queries | Code | |
| Maximum Building II | Code | ||
| ✔ | Stick Divisions | Huffman Coding greedy | Code |
| Stick Difference | Code | ||
| ✔ | Coding Company | Open and Close Interval DP | Code |
| Two Stacks Sorting | Code |