DSA Day 4 – Simple Problem, Important Insight Today I solved the “Contains Duplicate” problem on LeetCode. Problem: Check if any element appears more than once in an array. Initial Thought: -> Use nested loops to compare every pair -> Time Complexity: O(n²) ❌ Optimized Approach: -> Used HashMap to track elements -> While iterating, check if element already exists -> If yes → duplicate found Time Complexity: -> O(n) -> Space Complexity: O(n) Key Learning: -> Not every problem needs complex logic -> Choosing the right data structure makes a big difference -> Hashing is one of the most powerful tools in DSA What I Realized: Sometimes the simplest problems teach the most important concepts. Thanks to Pulkit Aggarwal sir for guiding me in DSA and helping me build strong fundamentals. Staying consistent, one day at a time. #DSA #LeetCode #Java #ProblemSolving #CodingJourney #100DaysOfCode
sameer khan’s Post
More Relevant Posts
-
🚀 Day 31/200 – DSA Journey Solved: Contains Duplicate (LeetCode) 🔍 Approach Used: - Sorted the array - Compared adjacent elements - If nums[i] == nums[i-1], duplicate exists ⚡ Complexity: - Time: O(n log n) - Space: O(1) 💡 Key Learning: Brute force approach (O(n²)) is simple but not efficient. Using sorting helps optimize the solution and reduces time complexity. 📈 Progress Insight: Learning to move from brute force to optimized solutions step by step. Consistency > Motivation #DSA #LeetCode #Java #ProblemSolving #CodingJourney #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 90 – DSA Journey | Binary Tree Paths Continuing my daily DSA practice, today I explored how to track and construct paths in a binary tree. 📌 Problem Practiced: Binary Tree Paths (LeetCode 257) 🔍 Problem Idea: Return all root-to-leaf paths in a binary tree as strings. 💡 Key Insight: While traversing the tree, we can build the path step by step. Once we reach a leaf node, we add the complete path to the result. 📌 Approach Used: • Use DFS traversal • Maintain a string to track the current path • At each node, append its value to the path • If it’s a leaf node → add the path to result • Continue exploring left and right subtrees 📌 Concepts Strengthened: • Tree traversal (DFS) • Recursion • Path tracking • String manipulation ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(h) (recursion stack) 🔥 Today’s takeaway: Tracking state (like a path) during recursion is a powerful technique for solving tree problems. On to Day 91! 🚀 #Day90 #DSAJourney #LeetCode #BinaryTree #DFS #Java #ProblemSolving #Coding #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day 15 of My DSA Journey Today’s problem: Array Rank Transform 💡 Problem Insight: Given an array, replace each element with its rank when the array is sorted. Rank starts from 1 Equal elements → same rank Ranks must be continuous (no gaps) 🧠 Approach: 🔹 Clone and sort the array 🔹 Use a HashMap to assign ranks to unique elements 🔹 Traverse original array and replace values using the map ⚡ Key Learning: 👉 This is a classic example of Coordinate Compression 👉 Helps reduce large values into a smaller ranked range 💻 Code Logic: Sort copy of array Assign rank only if element not already mapped Replace original values using the map 📊 Result: ✅ 43 / 43 test cases passed ⏱ Runtime: 31 ms 📈 Beat: 58.58% 💾 Memory: 74.74 MB (85.14% better than others) 💭 Takeaway: Simple problems can test clean thinking + handling duplicates properly. Hashing + sorting is a powerful combo 🔥 🔥 Consistency Check: Day 15 Complete Building discipline one problem at a time. #DSA #CodingJourney #LeetCode #Java #ProblemSolving #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🔥 DSA Challenge – Day 125/360 🚀 📌 Topic: Recursion 🧩 Problem: Combination Sum Problem Statement: Given an array of distinct integers and a target, return all unique combinations where numbers sum up to the target. Same element can be used multiple times. 🔍 Example: Input: candidates = [2,3,6,7], target = 7 Output: [[2,2,3],[7]] 💡 Approach: Backtracking 1️⃣ Step 1 – Start from index 0 and try picking each element 2️⃣ Step 2 – If element ≤ target, include it and reduce target 3️⃣ Step 3 – Backtrack (remove element) and move to next index ✔ Use recursion to explore all possibilities ✔ Reuse same element (stay on same index) ✔ Stop when target becomes 0 (valid answer) ✔ Skip when index reaches end ⏱ Complexity: Time: O(2^n * k) (k = avg length of combination) Space: O(k * x) (x = number of combinations) 📚 Key Learning: Backtracking is all about making choices, exploring, and undoing them efficiently. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #360DaysOfCode #LeetCode #Backtracking 🚀
To view or add a comment, sign in
-
-
🚀 Day 82 – DSA Journey | Same Tree using Recursion Continuing my daily DSA practice, today I worked on a problem that strengthened my understanding of tree comparison and recursion. 📌 Problem Practiced: Same Tree (LeetCode 100) 🔍 Problem Idea: Given two binary trees, determine whether they are identical in both structure and node values. 💡 Key Insight: To check if two trees are the same, we need to compare nodes at every level — both their values and their left & right subtrees. Recursion makes this process clean and intuitive. 📌 Approach Used: • If both nodes are null → trees match at this point • If one is null or values differ → trees are not the same • Recursively compare left subtrees • Recursively compare right subtrees • Both sides must match for the trees to be identical 📌 Concepts Strengthened: • Tree traversal • Recursion • Structural comparison • Base case handling ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(h) (recursion stack) 🔥 Today’s takeaway: Tree problems often become simple when broken down recursively — solve smaller subtrees to solve the whole tree. On to Day 83! 🚀 #Day82 #DSAJourney #LeetCode #BinaryTree #Recursion #Java #ProblemSolving #Coding #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🔥 DSA Challenge – Day 127/360 🚀 📌 Topic: Backtracking 🧩 Problem: Subsets II Problem Statement: Given an integer array that may contain duplicates, return all possible subsets such that the solution set does not contain duplicate subsets. 🔍 Example: Input: nums = [1,2,2] Output: [[], [1], [1,2], [1,2,2], [2], [2,2]] 💡 Approach: Backtracking + Sorting 1️⃣ Step 1 – Sort the array to group duplicate elements together 2️⃣ Step 2 – Use recursion to generate all subsets 3️⃣ Step 3 – Skip duplicate elements using condition (i != ind && nums[i] == nums[i-1]) ⏱ Complexity: Time: O(2^n) Space: O(n) (recursion stack + subset storage) 📚 Key Learning: Sorting + smart skipping of duplicates helps avoid repeated subsets in backtracking problems. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #360DaysOfCode #LeetCode #Backtracking
To view or add a comment, sign in
-
-
🚀 Solved a neat Difference Array problem today! 💡 Problem: Given an array and a set of range queries, determine whether it’s possible to make the entire array zero using the allowed operations. 🧠 Approach: Instead of applying each query directly (which would be slow), I used: • Difference Array for efficient range updates • Prefix Sum to compute actual impact at each index ⚡ Key Idea: Each query contributes to a range. By marking where the effect starts and ends, we can efficiently calculate how many times each index can be reduced. Then, for every index: • Compare available operations with required value • If available < required → not possible 📈 Complexity: O(n + q) — efficient and scalable 🔥 Key Learning: Using a Difference Array avoids repeated work and helps optimize range-based problems significantly. #LeetCode #DSA #Java #Coding #ProblemSolving #Arrays #Algorithms
To view or add a comment, sign in
-
-
Day 11/90 DSA Journey Today I implemented an efficient solution for the classic DSA problem “Subarray Sum Equals K” using Prefix Sum + HashMap. -> Approach: Maintain a running prefix sum while traversing the array. Use a HashMap to store the frequency of prefix sums. At each index, check if (currentSum - k) exists in the map. If it exists, it means there is a subarray ending at the current index with sum = k. -> Key Insight: If sum[j] - sum[i] = k, then the subarray (i+1 to j) has sum k. -> Code Highlights: Initialize map.put(0,1) to handle edge cases. Continuously update frequency of prefix sums. Efficient lookup using HashMap. -> Time Complexity: -> O(n) — We traverse the array only once. -> Space Complexity: -> O(n) — In the worst case, we store all prefix sums in the HashMap. -> Why this is powerful? This approach avoids nested loops (O(n²)) and optimizes the solution using hashing. #DSA #Java #LeetCode #Coding #Hashing #PrefixSum #ProblemSolving
To view or add a comment, sign in
-
-
🚀 DSA Preparation 💪 Solved this problem in my first attempt 🎯 Focused on finding the closest index using simple traversal and distance calculation. A good exercise to strengthen array fundamentals and logical thinking 🔥 🧠 Problem 🔎 Minimum Distance to the Target Element Given an array nums, a target, and a start index: 👉 Find an index i such that nums[i] == target 👉 Return the minimum absolute difference |i - start| 📌 It is guaranteed that the target exists in the array. Example Input: nums = [1,2,3,4,5], target = 5, start = 3 Output: 1 Input: nums = [1], target = 1, start = 0 Output: 0 ⚡ Key Learning 📌 Traverse the array and track minimum distance 📌 Use absolute difference for comparison 📌 Time Complexity: O(n) 📌 Space Complexity: O(1) First attempt success ✅ Improving DSA step by step 🚀 #DSA #LeetCode #Arrays #ProblemSolving #Java #Consistency
To view or add a comment, sign in
-
-
🔥 DSA Challenge – Day 123/360 🚀 📌 Topic: Recursion 🧩 Problem: Generate Parentheses Problem Statement: Given n pairs of parentheses, generate all combinations of well-formed (valid) parentheses. 🔍 Example: Input: n = 3 Output: ["((()))","(()())","(())()","()(())","()()()"] 💡 Approach: Backtracking 1️⃣ Step 1 – Start with an empty string and track open (oc) and close (cc) brackets 2️⃣ Step 2 – Add "(" if oc < n (we still have opening brackets left) 3️⃣ Step 3 – Add ")" only if cc < oc (to maintain valid structure) 👉 This ensures we only generate valid combinations (no extra filtering needed) ⏱ Complexity: Time: O(2ⁿ) (Catalan growth) Space: O(n) recursion stack 📚 Key Learning: Backtracking works best when we avoid invalid choices early, instead of fixing them later. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #123DaysOfCode #LeetCode #Backtracking
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