A comprehensive collection of Java programming exercises, algorithm problems, and coding challenges from various sources. This repository serves as a portfolio of problem-solving skills and Java proficiency.
java-practice/
├── leetcode/
│ ├── easy/
│ ├── medium/
│ ├── hard/
│ └── README.md
├── hackerrank/
│ ├── algorithms/
│ ├── data-structures/
│ └── README.md
├── labs/
│ ├── lab01/
│ ├── lab02/
│ └── README.md
├── codewars/
│ └── README.md
├── project-euler/
│ └── README.md
├── data/
│ ├── csv/
│ ├── txt/
│ └── README.md
├── utils/
│ └── Helper.java
├── .gitignore
└── README.md
- leetcode/: LeetCode problems organized by difficulty (easy/medium/hard)
- hackerrank/: HackerRank challenges categorized by topic
- labs/: Academic lab assignments and course exercises
- codewars/: Codewars kata solutions
- project-euler/: Project Euler mathematical problems
- data/: Input data files (CSV, TXT, JSON) used across problems
- utils/: Reusable utility classes and helper functions
- Java JDK 11 or higher
- Git installed on your machine
- GitHub account
-
Create a new repository on GitHub
- Go to https://github.com/new
- Name it
java-practice(or your preferred name) - Choose public or private
- DO NOT initialize with README (we'll push our own)
- Click "Create repository"
-
Clone the repository to your local machine
git clone https://github.com/YOUR_USERNAME/java-practice.git cd java-practice -
Create the folder structure
mkdir -p leetcode/{easy,medium,hard} mkdir -p hackerrank/{algorithms,data-structures} mkdir -p labs mkdir -p codewars mkdir -p project-euler mkdir -p data/{csv,txt} mkdir -p utils -
Create a .gitignore file
cat > .gitignore << 'EOF' # Compiled class files *.class # Log files *.log # Package Files *.jar *.war *.nar *.ear *.zip *.tar.gz *.rar # IDE-specific files .idea/ .vscode/ *.iml *.iws *.ipr .DS_Store # Eclipse .classpath .project .settings/ # Build directories target/ build/ out/ bin/ # Temporary files *.swp *.swo *~ EOF
-
Create this README file
- Copy this entire content into
README.md
- Copy this entire content into
-
Initial commit and push
git add . git commit -m "Initial repository setup with folder structure" git push -u origin main
Note: If your default branch is
masterinstead ofmain, usemasterin the command above.
-
Navigate to the appropriate folder
cd leetcode/easy -
Create your Java file
- Name format:
Problem001_TwoSum.javaorTwoSum.java - Include problem description in comments at the top
- Name format:
-
Write your solution
/** * Problem: Two Sum * Source: LeetCode #1 * Difficulty: Easy * Link: https://leetcode.com/problems/two-sum/ * * Description: * Given an array of integers nums and an integer target, * return indices of the two numbers that add up to target. */ public class TwoSum { public int[] twoSum(int[] nums, int target) { // Your solution here } public static void main(String[] args) { // Test cases } }
-
Test your solution locally
javac TwoSum.java java TwoSum
-
Stage and commit your changes
git add . git commit -m "Add LeetCode #1 - Two Sum solution"
-
Push to GitHub
git push
When a problem requires CSV or other input files:
-
Add the data file to the data folder
cp ~/Downloads/input.csv data/csv/leetcode_problem123_input.csv -
Reference it in your Java code
String filePath = "../../data/csv/leetcode_problem123_input.csv";
-
Commit both the code and data
git add leetcode/medium/Problem123.java git add data/csv/leetcode_problem123_input.csv git commit -m "Add LeetCode #123 with CSV input data" git push
# Check status of your repository
git status
# Add all changes
git add .
# Add specific file
git add path/to/file.java
# Commit with message
git commit -m "Your descriptive message"
# Push to GitHub
git push
# Pull latest changes
git pull
# View commit history
git log --oneline# Create and switch to new branch
git checkout -b feature/new-problem
# Switch back to main branch
git checkout main
# Merge branch into main
git merge feature/new-problem
# Delete branch after merge
git branch -d feature/new-problem- One problem per file - Keep solutions isolated
- Descriptive naming - Use clear, meaningful names
- Include problem metadata - Add source, difficulty, and link in comments
- Write test cases - Include
main()method with test cases - Document complexity - Note time and space complexity
Add [Source] #[Number] - [Problem Name]
Update [Source] #[Number] - [Improvement description]
Fix [Source] #[Number] - [Bug description]
Refactor [Source] #[Number] - [Refactoring description]
Examples:
Add LeetCode #217 - Contains DuplicateUpdate HackerRank - Improve time complexity for sorting problemFix Lab03 - Correct edge case handling
- LeetCode:
LC001_TwoSum.javaorTwoSum.java - HackerRank:
HR_SortingAlgorithm.java - Labs:
Lab01_Exercise01.java - Data files:
problem_name_input.csv
- ✅ Solve at least 3-5 problems per week
- ✅ Cover all difficulty levels
- ✅ Practice different algorithmic patterns
- ✅ Build a strong portfolio of solutions
- ✅ Regular commits to maintain GitHub streak
Create a PROGRESS.md file to track your journey:
# Progress Tracker
## Statistics
- Total Problems Solved: X
- LeetCode: X (Easy: X, Medium: X, Hard: X)
- HackerRank: X
- Labs: X
## Current Focus
- Topic: [e.g., Dynamic Programming]
- Goal: [e.g., Solve 10 DP problems this week]This is a personal practice repository, but if you'd like to share it:
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
This repository is for educational purposes. Problem descriptions are property of their respective platforms.
Happy Coding! 🚀