This repository contains Java solutions to problems from the CSES Problem Set, a collection of competitive programming practice problems.
CSES (Code Submission Evaluation System) is a comprehensive collection of algorithmic programming problems that cover various topics in competitive programming and algorithms. The problem set is widely used for learning and practicing competitive programming concepts.
The solutions are organized by problem categories:
src/
├── intro/ # Introductory Problems
├── sort/ # Sorting and Searching
├── dp/ # Dynamic Programming
├── graph/ # Graph Algorithms
├── math/ # Mathematics
├── rangesum/ # Range Queries
├── somepackage/ # Solution template (example file)
└── util/ # Utility classes (e.g., FastReader)
-
Introductory Problems (
intro/): Basic problems to get started with competitive programmingweird.java- Weird Algorithm (Collatz Conjecture)repetition.java- Repetitionsmissing.java- Missing Number
-
Sorting and Searching (
sort/): Problems involving sorting and searching techniquesdistinct.java- Distinct Numbersapartment.java- Apartmentsgondolas.java- Ferris Wheel / Gondola Lift
-
Dynamic Programming (
dp/): Classic dynamic programming problemsdice.java- Dice Combinations
-
Graph Algorithms (
graph/): Graph traversal and pathfinding problemslabyrinth.java- Labyrinthrooms.java- Counting Rooms
-
Mathematics (
math/): Mathematical and number theory problemsjosephus.java- Josephus Problempoint.java- Point Location Test
-
Range Queries (
rangesum/): Problems involving range-based operationsstaticrange.java- Static Range Sum Queriesrangemin.java- Static Range Minimum Queriesrangexor.java- Range XOR Queries
- Java Development Kit (JDK) 8 or higher
- A Java IDE (IntelliJ IDEA, Eclipse, VS Code, etc.) or command-line tools
-
Clone the repository:
git clone https://github.com/b423016/CSES_SOLN.git cd CSES_SOLN -
Open in your IDE:
- For IntelliJ IDEA: Open the project folder directly (the
.imlfile is already configured) - For other IDEs: Import as a Java project with
src/as the source folder
- For IntelliJ IDEA: Open the project folder directly (the
-
Compile and run (command line):
# Compile a specific solution from the project root javac -d out -cp src src/intro/weird.java # Run the compiled class java -cp out intro.weird
Each Java file contains a solution to a specific CSES problem. To use a solution:
- Navigate to the problem on CSES Problem Set
- Find the corresponding solution file in this repository
- Review the code to understand the approach
- Test the solution with sample inputs
- Submit to CSES for verification
Option 1: Using an IDE
- Open the desired
.javafile - Run the main method
- Provide input through the console
Option 2: Command Line
# From the project root directory
# Compile
javac -d out -cp src src/intro/weird.java
# Run
java -cp out intro.weirdFor the Weird Algorithm problem (intro/weird.java):
Input: 3
Output: 3 10 5 16 8 4 2 1
The repository includes helpful utilities:
util/FastReader.java: Fast input reader for competitive programming (optimized for large inputs)somepackage/Solution.java: Template file demonstrating the usage of FastReader - use this as a starting point for new solutions
Contributions are welcome! If you'd like to add more solutions or improve existing ones:
- Fork the repository
- Create a new branch for your solution (
git checkout -b add-problem-name) - Add your solution in the appropriate category folder
- Follow the existing code structure and naming conventions
- Test your solution on CSES
- Commit your changes (
git commit -m 'Add solution for Problem Name') - Push to your branch (
git push origin add-problem-name) - Open a Pull Request
- Use meaningful variable names
- Add comments for complex logic
- Follow Java naming conventions (camelCase for variables/methods, PascalCase for classes)
- Keep solutions efficient and optimized for competitive programming constraints
- Include the problem name or number as a comment at the top of the file
- CSES Problem Set - Official problem set
- CSES Problem Set Solutions - Statistics and discussion
- Competitive Programmer's Handbook - Free book by the CSES creator
This project is open source and available for educational purposes. Solutions are provided as-is for learning and reference.
- Problems are from the CSES Problem Set
- Created and maintained by competitive programming enthusiasts
These solutions are meant for learning purposes. It's recommended to attempt solving the problems yourself before referring to the solutions. Understanding the approach is more valuable than just copying the code.
Happy Coding! 🚀