Day 45/100 – #100DaysOfCode 🚀 | #Java #Hashing #SlidingWindow ✅ Problem Solved: Contains Duplicate III (LeetCode 220) 🧩 Problem Summary: Given an integer array and integers k and t, determine if there exist two distinct indices i and j such that: |i - j| ≤ k |nums[i] - nums[j]| ≤ t 💡 Approach Used: Used a Sliding Window + TreeSet to maintain numbers in a sorted structure. Steps: Traverse the array and maintain a window of at most size k. For each element x, find if there exists another element in the set such that |x - y| ≤ t. This is done using ceiling() to find the closest value ≥ x. Insert the element in TreeSet and remove the element that slides out. ⚙️ Time Complexity: O(n log k) 📦 Space Complexity: O(k) ✨ Takeaway: This problem teaches how ordered data structures like TreeSet help efficiently handle range queries in sliding window scenarios. #Java #TreeSet #SlidingWindow #LeetCode #ProblemSolving #100DaysOfCode #CodingChallenge
Mohd Haider’s Post
More Relevant Posts
-
Day 31/100 – #100DaysOfCode 🚀 | #Java #LeetCode #Sorting #Arrays ✅ Problem Solved: Maximum Gap ⚙️ 🧩 Problem Summary: Given an unsorted array, find the maximum difference between successive elements in its sorted form. You must solve it in linear time and space. 💡 Approach Used: Used Bucket Sort (Pigeonhole Principle) to achieve linear performance — ➤ Calculated global min & max. ➤ Divided range into buckets based on array size. ➤ Placed elements into buckets tracking min & max of each. ➤ Found maximum gap between successive non-empty buckets. ⚙️ Time Complexity: O(N) 📦 Space Complexity: O(N) ✨ Takeaway: This problem sharpened my understanding of bucket-based approaches and how sorting principles can be applied efficiently without direct sorting. ⚡ #Java #LeetCode #BucketSort #Sorting #ProblemSolving #100DaysOfCode #CodingChallenge
To view or add a comment, sign in
-
-
Day 50/100 – #100DaysOfCode 🚀 | #Java #Arrays #GreedyApproach ✅ Problem Solved: Minimum Operations to Convert All Elements to Zero (LeetCode) 🧩 Problem Summary: You’re given an array of integers. In one operation, you can subtract the smallest non-zero value from every non-zero element. Return the number of operations needed to make all elements zero. 💡 Approach Used: Instead of simulating operations (which would be inefficient), observe: Each distinct positive value in the array contributes exactly one operation. Because removing the smallest non-zero repeatedly is equivalent to counting how many unique positive values exist. So, Answer = Count of unique positive elements Why this works: Each distinct positive number represents one “level” of reduction until zero. ⚙️ Time Complexity: O(N) 📦 Space Complexity: O(N) (for set) ✨ Takeaway: This problem highlights how pattern recognition and mathematical simplification often outperform brute-force logic. #Java #LeetCode #MathLogic #GreedyAlgorithm #ProblemSolving #100DaysOfCode #CodingChallenge
To view or add a comment, sign in
-
-
Day 39/100 – #100DaysOfCode 🚀 | #Java #LeetCode #HashMap ✅ Problem Solved: Minimum Index Sum of Two Lists 🧩 Problem Summary: Given two string arrays, find the common strings with the smallest index sum (index in list1 + index in list2). If multiple answers exist, return all of them. 💡 Approach Used: ➤ Stored the elements of the first list in a HashMap with their indices. ➤ Iterated the second list and checked for matches. ➤ Tracked the minimum index sum and collected all strings that match that sum. This avoids nested loops and improves efficiency. ⚙️ Time Complexity: O(n + m) 📦 Space Complexity: O(n) ✨ Takeaway: HashMaps continue to be one of the most effective tools for reducing time complexity through direct lookups 🔍⚡ #Java #LeetCode #HashMap #DataStructures #ProblemSolving #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
Day 29/100 – #100DaysOfCode 🚀 | #Java #LeetCode #BinaryTree ✅ Problem Solved: Verify Preorder Serialization of a Binary Tree 🌲 🧩 Problem Summary: Given a string representing a preorder serialization of a binary tree, determine if it’s valid. Example: "9,3,4,#,#,1,#,#,2,#,6,#,#" → ✅ valid "1,#" → ❌ invalid 💡 Approach Used: Used the slot-counting method 🧠 Each node uses one slot and non-null nodes create two new slots. Process the preorder string, ensuring slots never go negative and exactly zero remain at the end. ⚙️ Time Complexity: O(n) 📦 Space Complexity: O(1) ✨ Takeaway: This problem teaches how binary tree structure can be validated with simple counting logic — no need to rebuild the tree! 🌱 #Java #LeetCode #BinaryTree #100DaysOfCode #ProblemSolving #CodingChallenge
To view or add a comment, sign in
-
-
🚀 LeetCode #58 – Length of Last Word (Java Solution) Today I solved a classic string problem that tests how well you handle edge cases and string traversal logic. 🧩 Problem Statement: Given a string s consisting of words and spaces, return the length of the last word in the string. A word is defined as a maximal substring consisting of non-space characters only. 🧠 Dry Run Example Input: " fly me to the moon " ➡ After skipping spaces → "fly me to the moon" ➡ Last word = "moon" ➡ Output: 4 ⚙️ Time & Space Complexity Time Complexity: O(n) — we traverse the string once (from the end to the start). Space Complexity: O(1) — no extra space used apart from a few variables. 💡 Key Takeaways: ✅ Learned how to handle trailing spaces properly before counting. ✅ Strengthened understanding of string traversal in reverse. ✅ Explored an alternative approach using trim() + split("\\s+") for readability. ✅ Remembered to test with edge cases like "a" or "Hello " to ensure correctness. Every small problem like this helps in building stronger fundamentals 💪 #Java #LeetCode #ProblemSolving #CodingJourney #LearningInPublic #75DaysOfCode #DataStructures #Algorithms
To view or add a comment, sign in
-
-
Day 47/100 – #100DaysOfCode 🚀 | #Java #Arrays #InPlaceAlgorithms ✅ Problem Solved: First Missing Positive (LeetCode 41) 🧩 Problem Summary: Given an unsorted array, find the smallest missing positive integer. The solution must run in O(n) time and constant extra space. 💡 Approach Used: This is not a direct sorting or hashing problem — the key is index positioning. Logic: The answer must lie within 1 to n+1. Place each positive number x at index x-1 if possible. Then scan to find the first index where nums[i] != i+1. Steps: Iterate and swap values into their correct position. Ignore values ≤0 or >n. Final scan to find the first missing positive. ⚙️ Time Complexity: O(n) 📦 Space Complexity: O(1) ✨ Takeaway: This problem teaches how index-based hashing can eliminate the need for extra space — very common in interview-style optimization problems. #Java #LeetCode #Algorithm #Array #ProblemSolving #100DaysOfCode #CodingChallenge
To view or add a comment, sign in
-
-
Day 44/100 – #100DaysOfCode 🚀 | #Java #LinkedList ✅ Problem Solved: Reverse Nodes in k-Group (LeetCode 25) 🧩 Problem Summary: Given a linked list, reverse every group of k consecutive nodes. If the last group has fewer than k nodes, leave it as is. 💡 Approach Used: We first count whether k nodes exist — only then we reverse that segment. Steps: Traverse ahead k nodes to ensure reversal is possible. Reverse exactly k nodes iteratively. Recursively process the remaining list. Connect the reversed part with the next processed segment. This allows efficient in-place operations without extra memory. ⚙️ Time Complexity: O(n) 📦 Space Complexity: O(1) (Reversing done in-place) ✨ Takeaway: This problem strengthens understanding of pointer manipulation and linked list segment handling — vital for clean and bug-free list operations. #Java #LinkedList #Pointers #Recursion #LeetCode #ProblemSolving #100DaysOfCode #CodingChallenge
To view or add a comment, sign in
-
-
🌳 Day 46 of #LeetCodeJourney Problem: 100. Same Tree ✅ Today’s challenge was about comparing two binary trees — checking if they’re structurally identical and have the same node values. A neat recursive problem that refreshes the basics of tree traversal and recursion! 💡 Key takeaway: If you can break a problem down into smaller identical subproblems — recursion will always have your back. #LeetCode #100DaysOfCode #Java #DSA #BinaryTree #Recursion #CodingJourney
To view or add a comment, sign in
-
-
Day 28/100 – #100DaysOfCode 🚀 | #Java #LeetCode #DynamicProgramming ✅ Problem Solved: Scramble String 🔀 🧩 Problem Summary: Given two strings s1 and s2, determine whether one is a scrambled version of the other. A string is scrambled by recursively dividing it into two non-empty substrings and swapping them. 💡 Approach Used: Implemented Recursion + Memoization using a HashMap for overlapping subproblems. Used character frequency checks to prune unnecessary recursion calls. Used Java’s BiFunction with inline helper logic for recursion. ⚙️ Time Complexity: O(n⁴) (due to substring operations and recursion) 📦 Space Complexity: O(n²) ✨ Takeaway: Even complex recursive problems can be optimized efficiently with Memoization and early pruning. 🚀 #Java #LeetCode #DynamicProgramming #Recursion #ProblemSolving #100DaysOfCode #CodingChallenge
To view or add a comment, sign in
-
-
🔥 #100DaysOfDSA — Day 30/100 Topic: Reverse an Array in Java 🔁 💡 What I Did Today: Today, I explored how to reverse an array manually using the two-pointer approach. Instead of relying on built-in methods, I learned how to swap elements from both ends until the array is completely reversed. 🧠 Logic Used: Initialize two pointers: start = 0 (beginning of array) end = numbers.length - 1 (end of array) While start < end: Swap numbers[start] and numbers[end] Move pointers inward → start++ and end-- 📊 Example: Input → {2, 4, 6, 8, 10} Output → {10, 8, 6, 4, 2} ⚙️ Time Complexity: O(n) — each element is swapped once. O(1) space — done in-place without using extra arrays. ✨ Takeaway: Learning to reverse an array manually helps strengthen the concept of pointers, loops, and in-place operations. Sometimes the simplest logic gives the biggest "aha!" moment 💡 #100DaysOfCode #Day30 #Java #DSA #Arrays #ProblemSolving #CodingJourney #LearnInPublic #DeveloperLife #CodeNewbie #LogicBuilding
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