🚀 Day 22 / 180 – DSA with Java 🚀 📘 Topic Covered: Hashing & Sequence Detection 🧩 Problem Solved: Longest Consecutive Sequence Problem: Given an unsorted array of integers, find the length of the longest consecutive elements sequence in O(n) time. Approach: Stored all elements in a HashSet for O(1) lookups. For each number, only started counting if it was the beginning of a sequence (i.e., the previous number was not present). Then extended the sequence forward to find its length. Key Learning: ✔️ Using HashSet for efficient lookups ✔️ Identifying sequence starting points to avoid redundancy ✔️ Achieving O(n) time complexity for an otherwise sorting-based problem If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Hashing #ProblemSolving #Consistency
Java DSA: Longest Consecutive Sequence with Hashing
More Relevant Posts
-
🚀 Day 23 / 180 – DSA with Java 🚀 📘 Topic Covered: Linked List Manipulation 🧩 Problem Solved: Delete Node in a Linked List Problem: Given a node in a singly linked list (not the head), delete that node without access to the previous node. Approach: Since the previous node is not accessible, copied the value of the next node into the current node and updated the pointer to skip the next node, effectively deleting it. Key Learning: ✔️ Thinking differently when constraints change ✔️ Understanding pointer manipulation in linked lists ✔️ Solving problems by modifying node structure directly If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #LinkedList #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 34 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Basic Construction 🧩 Problem Solved: Concatenation of Array Problem: Given an integer array nums, create a new array that contains the elements of nums twice in sequence. Approach: Created a new array with double the size of the original array and filled the first half with the original elements, then copied the same elements again into the second half. Key Learning: ✔️ Practicing array construction and indexing ✔️ Understanding how to manipulate array sizes ✔️ Writing clean logic for simple transformation problems If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 33 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Index Manipulation 🧩 Problem Solved: Shuffle the Array Problem: Given an array in the form [x1, x2, ..., xn, y1, y2, ..., yn], rearrange it to [x1, y1, x2, y2, ..., xn, yn]. Approach: Used two pointers to track elements from the first and second halves of the array, then alternately placed them into a new array to achieve the required shuffle pattern. Key Learning: ✔️ Managing multiple pointers in array problems ✔️ Practicing index-based rearrangement ✔️ Maintaining correct ordering while constructing a new array If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 29 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Two-Pointer Technique 🧩 Problem Solved: Container With Most Water Problem: Given an array where each element represents the height of a vertical line, find two lines that together with the x-axis form a container that holds the maximum amount of water. Approach: Used a two-pointer strategy starting from both ends of the array. Calculated the water area using the shorter height and the distance between pointers, then moved the pointer with the smaller height to try finding a better container. Key Learning: ✔️ Efficient use of two-pointer technique ✔️ Understanding how pointer movement impacts optimization ✔️ Reducing brute-force O(n²) solutions to O(n) If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 25 / 180 – DSA with Java 🚀 📘 Topic Covered: Binary Search (First & Last Occurrence) 🧩 Problem Solved: Find First and Last Position of Element in Sorted Array Problem: Given a sorted array and a target value, find the starting and ending position of the target in O(log n) time. If not found, return [-1, -1]. Approach: Used Binary Search twice — • First to find the leftmost (first) occurrence • Then to find the rightmost (last) occurrence By carefully adjusting the search boundaries, ensured both positions were located efficiently. Key Learning: ✔️ Extending binary search for range queries ✔️ Handling boundary conditions carefully ✔️ Maintaining O(log n) time complexity If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #BinarySearch #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 DSA Learning Journey | Day 9 | Java Solved “125. Valid Palindrome.” 💡 Key Idea: Used Two Pointers while ignoring non-alphanumeric characters and comparing characters in a case-insensitive way. ⚙ Implementation • Language: Java • Time Complexity: O(n) • Space Complexity: O(1) 📚 Learning how two-pointer technique simplifies string validation problems. #Java #DSA #LeetCode #ProblemSolving #TwoPointers #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 DSA Learning Journey | Day 5 | Java Solved “Maximum Product Subarray.” 💡 Key Idea: Tracked both maximum and minimum products at each step since a negative number can flip the sign and turn a minimum into a maximum. ⚙ Implementation • Language: Java • Time Complexity: O(n) • Space Complexity: O(1) 📚 Learning how handling negative numbers and dynamic updates is important in product-based subarray problems. #Java #DSA #LeetCode #ProblemSolving #JavaDeveloper #Algorithms
To view or add a comment, sign in
-
-
🚀 Day 30 / 180 – DSA with Java 🚀 📘 Topic Covered: Strings & Sorting Technique 🧩 Problem Solved: Longest Common Prefix Problem: Given an array of strings, find the longest common prefix shared among all the strings. Approach: Sorted the array of strings and compared only the first and last strings. Since sorting groups similar prefixes together, the common prefix between these two strings represents the common prefix for the entire array. Key Learning: ✔️ Using sorting to simplify string comparison problems ✔️ Observing patterns to reduce unnecessary checks ✔️ Efficient prefix detection in string arrays If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Strings #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 28 / 180 – DSA with Java 🚀 📘 Topic Covered: Strings & Sliding Window 🧩 Problem Solved: Divisor Substrings Problem: Given an integer num and an integer k, find the number of substrings of length k from the digits of num such that the substring value divides num. Approach: Converted the number to a string and used a sliding window of size k to extract substrings. Each substring was converted back to an integer and checked whether it divides the original number. Key Learning: ✔️ Applying sliding window technique on strings ✔️ Converting between numeric and string representations ✔️ Handling edge cases like division by zero If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Strings #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 31 / 180 – DSA with Java 🚀 📘 Topic Covered: Strings & Substring Search 🧩 Problem Solved: Find the Index of the First Occurrence in a String Problem: Given two strings haystack and needle, return the index of the first occurrence of needle in haystack. If it is not present, return -1. Approach: Traversed the main string and checked potential starting positions where the first character matched. Then compared the substring of the same length as the target string to verify a complete match. Key Learning: ✔️ Understanding substring search logic ✔️ Optimizing comparisons by checking the first character first ✔️ Practicing careful boundary handling in string traversal If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Strings #ProblemSolving #Consistency
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development