From 101e42244581831d533435915806887fdbcf0ddc Mon Sep 17 00:00:00 2001 From: ISHA AGGARWAL <244146795+IshaAggarwalDev@users.noreply.github.com> Date: Mon, 23 Feb 2026 00:01:02 +0530 Subject: [PATCH 1/3] Create 0001_TwoSum_HashMap.java --- 0001_TwoSum_HashMap.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 0001_TwoSum_HashMap.java diff --git a/0001_TwoSum_HashMap.java b/0001_TwoSum_HashMap.java new file mode 100644 index 0000000..691a685 --- /dev/null +++ b/0001_TwoSum_HashMap.java @@ -0,0 +1,17 @@ +class Solution { + public int[] twoSum(int[] nums, int target) { + HashMap map = new HashMap<>(); + + for (int i = 0; i < nums.length; i++) { + int complement = target - nums[i]; + + if (map.containsKey(complement)) { + return new int[] { map.get(complement), i }; + } + + map.put(nums[i], i); + } + + return new int[] {}; + } +} From 56292d2b86137b675c3e4b463d5b4662e635e064 Mon Sep 17 00:00:00 2001 From: ISHA AGGARWAL <244146795+IshaAggarwalDev@users.noreply.github.com> Date: Mon, 23 Feb 2026 00:01:51 +0530 Subject: [PATCH 2/3] Create 0128_Longest_Consecutive_Sequence.java --- 0128_Longest_Consecutive_Sequence.java | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 0128_Longest_Consecutive_Sequence.java diff --git a/0128_Longest_Consecutive_Sequence.java b/0128_Longest_Consecutive_Sequence.java new file mode 100644 index 0000000..65c0494 --- /dev/null +++ b/0128_Longest_Consecutive_Sequence.java @@ -0,0 +1,34 @@ +import java.util.HashSet; + +class Solution { + public int longestConsecutive(int[] nums) { + + HashSet set = new HashSet<>(); + + // Add all numbers to set + for (int num : nums) { + set.add(num); + } + + int longest = 0; + + for (int num : set) { + + // Check if it's the start of a sequence + if (!set.contains(num - 1)) { + + int currentNum = num; + int currentStreak = 1; + + while (set.contains(currentNum + 1)) { + currentNum++; + currentStreak++; + } + + longest = Math.max(longest, currentStreak); + } + } + + return longest; + } +} From 9749db9106c600eba4be749247171db6fa1329dd Mon Sep 17 00:00:00 2001 From: ISHA AGGARWAL <244146795+IshaAggarwalDev@users.noreply.github.com> Date: Mon, 23 Feb 2026 00:07:07 +0530 Subject: [PATCH 3/3] Update README.md --- README.md | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 9f0fa45..a0ad2c0 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,19 @@ -# LeetCode Solutions +# Hashing -This repository contains my solutions to LeetCode problems as part of my Data Structures and Algorithms practice. +## 1. Two Sum +Problem Link: https://leetcode.com/problems/two-sum/ +Difficulty: Easy +### Approach : HashMap (Optimized) +Time Complexity: O(n) +Space Complexity: O(n) +### Concepts Used: +Array Traversal,HashMap,Complement Technique,Single Pass Algorithm,Key-Value Mapping -The goal of this repository is to improve problem-solving skills and prepare for technical interviews and placements. - -## Topics Covered -- Arrays -- Strings -- Linked List -- Stack -- Queue -- Recursion -- Hashing -- Binary-Search -- Prefix-Sum -- Math +## 128. Longest Consecutive Sequence +Problem Link: https://leetcode.com/problems/longest-consecutive-sequence/ +Difficulty: Medium +### Approach: HashSet (Optimized) +Time Complexity: O(n) +Space Complexity: O(n) +### Concepts Used: +HashSet, Sequence Pattern, Array Traversal