A comprehensive collection of Data Structures & Algorithms implementations and LeetCode problem solutions in Java. This repository demonstrates proficiency in algorithmic thinking, problem-solving, and clean code practices.
- About
- Problem Categories
- Algorithms Implemented
- Project Structure
- Getting Started
- Solutions Overview
- Tech Stack
- Learning Resources
- Contributing
This repository serves as a personal learning journey and portfolio showcase for mastering data structures and algorithms using Java. Each solution is crafted with:
- β Clean, readable code with proper naming conventions
- β Optimized algorithms focusing on time and space complexity
- β Well-documented solutions with comments explaining key logic
- β Multiple approaches (brute force to optimal) where applicable
- β Working test cases in main methods for verification
- Three Sum - Finding triplets that sum to zero
- Group Anagrams - Grouping strings by anagram patterns
- Longest Substring - Finding longest substring without repeating characters
- Container With Most Water - Two-pointer optimization problem
- Median of Two Sorted Arrays - Binary search on sorted arrays
- Merge Two Sorted Arrays - In-place merging technique
- Reverse Linked List - Iterative and recursive approaches
- Add Two Numbers - Arithmetic operations on linked lists
- Single Number - Bit manipulation and hash set techniques
- Missing Number - Mathematical approach to find missing element
- Remove Duplicates II - Frequency-based duplicate removal
- Rotting Oranges - Multi-source BFS problem
- Word Search - Backtracking and DFS on 2D grid
- Combination Sum - Finding all combinations that sum to target
- Best Price - Optimization problem
- Coin Change II - DP solution for number of ways
- Last Stone Weight - Heap-based simulation
- Lucky Number - Number theory and pattern recognition
| Algorithm | Time Complexity | Space Complexity | Implementation |
|---|---|---|---|
| Bubble Sort | O(nΒ²) | O(1) | BubbleSort.java |
| Selection Sort | O(nΒ²) | O(1) | SelectionSort.java |
| Quick Sort | O(n log n) avg | O(log n) | QuickSort.java |
- Optimized Bubble Sort with early termination for sorted arrays
- Hoare's Partition Scheme in Quick Sort for better performance
- Detailed comments explaining algorithm logic
java-practice/
βββ src/
β βββ main/
β βββ java/
β βββ com/
β βββ dsa/ # Core DSA implementations
β β βββ BubbleSort.java
β β βββ SelectionSort.java
β β βββ QuickSort.java
β βββ practice/ # LeetCode-style problems
β βββ ThreeSum.java
β βββ GroupAnagram.java
β βββ MedianOfTwoSortedArray.java
β βββ RottingOrange.java
β βββ CombinationSum.java
β βββ WordSearch.java
β βββ ... (15+ more solutions)
βββ pom.xml # Maven configuration
βββ README.md
- Java 17 or higher
- Maven 3.x
- IDE (IntelliJ IDEA, Eclipse, or VS Code recommended)
git clone https://github.com/arafat2020/java-parc.git
cd java-parcmvn clean compileEach solution has a main method for testing:
# Example: Run Quick Sort
mvn exec:java -Dexec.mainClass="com.dsa.QuickSort"
# Example: Run Three Sum
mvn exec:java -Dexec.mainClass="com.practice.ThreeSum"Or use your IDE to run individual files directly.
Problem: Find all unique triplets that sum to zero.
Approach: Two-pointer technique with duplicate handling
Complexity: O(nΒ²) time, O(1) space
File: ThreeSum.java
Problem: Group strings that are anagrams of each other.
Approach: HashMap with sorted string as key
Complexity: O(n * k log k) time, O(n) space
File: GroupAnagram.java
Problem: Find median of two sorted arrays.
Approach: Two-pointer merge technique (optimized)
Complexity: O(m + n) time, O(1) space
File: MedianOfTwoSortedArray.java
Implementation: Hoare's partition scheme
Optimization: In-place sorting with divide-and-conquer
Complexity: O(n log n) average, O(nΒ²) worst case
File: QuickSort.java
Problem: Find minimum time to rot all oranges in grid. Approach: Breadth-First Search (BFS) with level-order traversal Complexity: O(m * n) time, O(m * n) space File: RottingOrange.java
| # | Problem | Difficulty | Topics | File |
|---|---|---|---|---|
| 1 | Add Two Numbers | Medium | Linked List | AddTowNumber.java |
| 2 | Best Price | Medium | Greedy/DP | BestPrice.java |
| 3 | Combination Sum | Medium | Backtracking | CombinationSum.java |
| 4 | Group Anagrams | Medium | Hash Table | GroupAnagram.java |
| 5 | Last Stone Weight | Easy | Heap | LastStoneWeight.java |
| 6 | Longest Palindromic Substring | Medium | String/Two Pointers | LongestPalindromicSubstring.java |
| 7 | Longest Substring | Medium | Sliding Window | LongestSubString.java |
| 8 | Lucky Number | Easy | Math | LuckyNumber.java |
| 9 | Median of Two Sorted Arrays | Hard | Binary Search | MedianOfTwoSortedArray.java |
| 10 | Merge Two Sorted Arrays | Easy | Two Pointers | MergeTwoSortedArray.java |
| 11 | Missing Number | Easy | Math/Bit | MissingNumber.java |
| 12 | Remove Duplicates II | Medium | Array | RemoveDuplicateTwo.java |
| 13 | Reverse Linked List | Easy | Linked List | ReverseLinkedList.java |
| 14 | Rotting Oranges | Medium | BFS/Graph | RottingOrange.java |
| 15 | Single Number | Easy | Bit Manipulation | SingleNumber.java |
| 16 | Three Sum | Medium | Two Pointers | ThreeSum.java |
| 17 | Container With Most Water | Medium | Two Pointers | WaterContainer.java |
| 18 | Word Search | Medium | Backtracking/DFS | WordSearch.java |
| 19 | Coin Change II | Medium | DP/Recursion | CoinChange.java |
| 20 | Zigzag Conversion | Medium | String | ZigzagConversion.java |
- Language: Java 17
- Build Tool: Maven
- Development: Object-Oriented Programming, Clean Code Principles
- Concepts: Data Structures, Algorithms, Time/Space Complexity Analysis
Resources that helped in this journey:
- LeetCode - Problem practice platform
- GeeksforGeeks - Algorithm tutorials
- Big-O Cheat Sheet - Complexity reference
- Java Documentation - Official Java docs
Contributions, issues, and feature requests are welcome! Feel free to:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is open source and available for learning purposes.
Arafat
- GitHub: @arafat2020
- Repository: java-parc
β Star this repository if you find it helpful!
πΌ Actively practicing and adding new solutions regularly
π― Goal: Master DSA and ace technical interviews