Loading repository data…
Loading repository data…
be-a-guptaji / repository
DSA - Data Structures and Algorithms: A collection of optimized Java solutions to common problems, categorized by difficulty, to help with coding interview preparation.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
DSA is a collection of Java solutions to common data structure and algorithm (DSA) problems. This repository is designed to help developers and learners improve their problem-solving skills and prepare for coding interviews.
The problems cover a wide range of difficulty levels — from easy to hard — and are categorized into various sections such as Arrays, Linked Lists, Stacks, Queues, Trees, Dynamic Programming, and more. Each solution follows optimal approaches, providing a step-by-step explanation of the thought process and the reasoning behind each algorithm.
The project is organized into folders based on problem categories. Each category is further divided into difficulty levels (Easy, Medium, Hard). Here’s how the folder structure looks:
graph TD
A[Root]
A --> B[Topic-A]
B --> C[Easy]
B --> D[Medium]
B --> E[Hard]
A --> F[Topic-B]
F --> G[Easy]
F --> H[Medium]
F --> I[Hard]
Example folder structure:
DSA:
├── LICENSE
├── .gitignore
├───Arrays
│ ├───Easy
│ ├───Hard
│ └───Medium
├───Backtracking
│ ├───Hard
│ └───Medium
├───BinarySearchAndSorting
│ ├───Easy
│ ├───Hard
│ └───Medium
├───BitManipulation
│ ├───Easy
│ └───Medium
├───DynamicProgramming
│ ├───Easy
│ ├───Hard
│ └───Medium
├───Graphs
│ ├───Easy
│ ├───Hard
│ └───Medium
├───Greedy
│ ├───Hard
│ └───Medium
├───HeapsAndPriorityQueues
│ ├───Hard
│ └───Medium
├───LinkedList
│ ├───Easy
│ ├───Hard
│ └───Medium
├───Maths
│ ├───Easy
│ └───Medium
├───StacksAndQueues
│ ├───Easy
│ ├───Hard
│ └───Medium
├───SystemDesign
│ ├───Easy
│ ├───Hard
│ └───Medium
├───Trees
│ ├───Easy
│ ├───Hard
│ └───Medium
└───TwoPointersAndSlidingWindow
├───Easy
├───Hard
└───Medium
Each Java file in this repository follows a clear and standardized structure to ensure consistency and readability. Here’s how each file is structured:
main method is provided to test the solution with sample inputs.Here’s an example of a Java file for the problem Two Sum from LeetCode:
/*
LeetCode Problem: https://leetcode.com/problems/two-sum/
Question: 1. Two Sum
Problem Statement:
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example 1:
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
Constraints:
- 2 <= nums.length <= 10^4
- -10^9 <= nums[i] <= 10^9
- -10^9 <= target <= 10^9
*/
/*
Approach:
We solve this problem using a HashMap to store the numbers and their indices.
We iterate through the array and check if the complement of the current number exists in the HashMap.
If it does, we return the indices of the current number and the complement.
If the complement does not exist, we add the current number to the HashMap with its index as the value.
Time Complexity: O(n), where n is the number of elements in the array.
Space Complexity: O(n), where n is the number of elements in the array.
*/
package Arrays.Easy;
public class _1_Two_Sum {
// Method to find two indices of numbers adding up to target
public static int[] twoSum(int[] nums, int target) {
java.util.Map<Integer, Integer> map = new java.util.HashMap<>();
for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if (map.containsKey(complement)) {
// Found the pair
return new int[] { map.get(complement), i };
}
map.put(nums[i], i);
}
// If no solution found, return null
return null;
}
// Main method to test twoSum
public static void main(String[] args) {
int[] nums = { 2, 7, 11, 15 };
int target = 9;
int[] result = twoSum(nums, target);
if (result != null) {
System.out.println("Indices: " + result[0] + ", " + result[1]);
} else {
System.out.println("No two sum solution found.");
}
}
}
MIT License © 2025 Be-A-Guptaji DSA
👨💻 Aryan Baadlas
📧 aryanbaadlas@gmail.com
If you like this project, give it a star ⭐ on GitHub!