Skip to content

Latest commit

 

History

History
264 lines (192 loc) · 12.2 KB

File metadata and controls

264 lines (192 loc) · 12.2 KB

🚀 Java DSA & Problem Solving Practice

Java Maven LeetCode PRs Welcome

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.

📋 Table of Contents

🎯 About

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

📊 Problem Categories

Arrays & Strings

  • 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

Linked Lists

  • Reverse Linked List - Iterative and recursive approaches
  • Add Two Numbers - Arithmetic operations on linked lists

Hash Tables & Sets

  • Single Number - Bit manipulation and hash set techniques
  • Missing Number - Mathematical approach to find missing element
  • Remove Duplicates II - Frequency-based duplicate removal

Graphs & BFS/DFS

  • Rotting Oranges - Multi-source BFS problem
  • Word Search - Backtracking and DFS on 2D grid

Backtracking & Recursion

  • Combination Sum - Finding all combinations that sum to target
  • Letter Combinations of Phone Number - Generate all letter combinations from phone digits
  • Word Search - Backtracking and DFS on 2D grid

Greedy & Dynamic Programming

  • Best Price - Optimization problem
  • Coin Change II - DP solution for number of ways
  • Last Stone Weight - Heap-based simulation
  • Target Sum - DP with memoization to find ways to reach target

Mathematical Problems

  • Lucky Number - Number theory and pattern recognition
  • Palindrome Number - Check if number is palindrome without string conversion
  • Reverse Integer - Reverse digits with overflow handling

🔧 Algorithms Implemented

Sorting Algorithms

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

Key Features:

  • Optimized Bubble Sort with early termination for sorted arrays
  • Hoare's Partition Scheme in Quick Sort for better performance
  • Detailed comments explaining algorithm logic

📁 Project Structure

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

🚀 Getting Started

Prerequisites

  • Java 17 or higher
  • Maven 3.x
  • IDE (IntelliJ IDEA, Eclipse, or VS Code recommended)

Clone the Repository

git clone https://github.com/arafat2020/java-parc.git
cd java-parc

Build the Project

mvn clean compile

Run Individual Solutions

Each 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.

💡 Solutions Overview

Featured Solutions

🔹 Three Sum (LeetCode #15)

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

🔹 Group Anagrams (LeetCode #49)

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

🔹 Median of Two Sorted Arrays (LeetCode #4)

Problem: Find median of two sorted arrays.
Approach: Two-pointer merge technique (optimized)
Complexity: O(m + n) time, O(1) space
File: MedianOfTwoSortedArray.java

🔹 Quick Sort

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

🔹 Rotting Oranges (LeetCode #994)

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

Complete Problem List

# 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
21 Letter Combinations Phone Medium Backtracking LetterCombinationsPhoneNumber.java
22 Palindrome Number Easy Math PalindromeNumber.java
23 Reverse Integer Medium Math/String ReverseInteger.java
24 Target Sum Medium DP/Memoization TargetSum.java

🛠 Tech Stack

  • Language: Java 17
  • Build Tool: Maven
  • Development: Object-Oriented Programming, Clean Code Principles
  • Concepts: Data Structures, Algorithms, Time/Space Complexity Analysis

📚 Learning Resources

Resources that helped in this journey:

🤝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📝 License

This project is open source and available for learning purposes.

👨‍💻 Author

Arafat


Star this repository if you find it helpful!

💼 Actively practicing and adding new solutions regularly

🎯 Goal: Master DSA and ace technical interviews