Day 41/100 | #100DaysOfDSA 💻🚀 Today’s problem: Find the Duplicate Number Goal: Given an array with n + 1 numbers where each number is in the range [1, n], find the duplicate number without modifying the array and using constant extra space. Approach: Binary Search on Answer Idea: • The duplicate must lie in the range 1 → n • Count how many numbers are ≤ mid • If the count is greater than mid → duplicate is in the left half • Otherwise search the right half Key insight: Using the pigeonhole principle, if more numbers fall in a range than expected, a duplicate must exist there. Time Complexity: O(n log n) Space Complexity: O(1) Big takeaway: Binary search isn’t just for sorted arrays — it can also be applied on the range of possible answers. Day 41 — patterns getting clearer. 🔥 #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearch #Java #CodingJourney #InterviewPrep #ProblemSolving #TechCommunity
Yogesh ..’s Post
More Relevant Posts
-
Day 61/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Median of Two Sorted Arrays A classic hard problem with a clever binary search approach. Problem idea: Find the median of two sorted arrays without fully merging them. Key idea: Use binary search on the smaller array to partition both arrays. Why? • We want left half and right half to be balanced • All elements in left ≤ all elements in right How it works: • Pick a cut in array1 • Derive cut in array2 • Check partition validity using boundary elements If valid → we found the median If not → adjust the partition Time Complexity: O(log(min(m, n))) Space Complexity: O(1) Big takeaway: Binary search isn’t just for searching — it can be used to optimize partitions and positions. This one really builds intuition. 🔥 Day 61 done. #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearch #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 58/100 | #100DaysOfDSA 🔄🔍 Today’s problem: Search in Rotated Sorted Array A twist on Binary Search with a rotated array. Key idea: Even though the array is rotated, one half is always sorted. Approach: • Use binary search • Find mid element • Check which half is sorted (left or right) • Decide if target lies in the sorted half • Narrow the search accordingly Why it works: At every step, we eliminate half of the search space just like standard binary search. Time Complexity: O(log n) Space Complexity: O(1) Big takeaway: Understanding the structure of the problem helps adapt classic algorithms like binary search. Rotation doesn’t break order — it just shifts it. 🔥 Day 58 done. #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearch #Arrays #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 59/100 | #100DaysOfDSA 🔍⚡ Today’s problem: Single Element in a Sorted Array A clever Binary Search problem with a twist. Key observation: In a sorted array where every element appears twice except one, pairs follow a pattern. Before the single element: • First occurrence → even index • Second occurrence → odd index After the single element: • Pattern breaks Approach: • Use binary search • Check mid with its pair using index trick (mid ^ 1) • If nums[mid] == nums[mid ^ 1] → move right • Else → move left This helps pinpoint where the pattern breaks. Time Complexity: O(log n) Space Complexity: O(1) Big takeaway: Bit manipulation + pattern observation can simplify binary search problems significantly. Small tricks → big optimizations. 🔥 Day 59 done. #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearch #BitManipulation #Arrays #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 57/100 | #100DaysOfDSA ⛰️🔍 Today’s problem: Peak Index in a Mountain Array A perfect use-case of Binary Search on a pattern. Key observation: The array increases → reaches a peak → then decreases. Approach: • Use binary search on the index • Compare mid with mid + 1 • If arr[mid] > arr[mid + 1] → we are on the decreasing side → move left • Else → we are on the increasing side → move right This guarantees we always move toward the peak. Time Complexity: O(log n) Space Complexity: O(1) Big takeaway: Binary search isn’t just for sorted arrays — it works on patterns too. Recognizing these patterns is a game changer. 🔥 Day 57 done. #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearch #Arrays #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 52/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Group Anagrams Classic hashing + string pattern. String properties: • Anagrams contain the same characters • Only the order of characters differs • Need to group similar character patterns together Key idea: Use character frequency as a unique key. Why? • Anagrams will always have identical character counts • This gives a consistent way to group strings • More efficient than sorting every string Approach: • Traverse each string in the array • Count frequency of each character (a–z) • Convert frequency array into a string key • Store strings in a HashMap based on this key • Return all grouped values Time Complexity: O(n * k) Space Complexity: O(n * k) Big takeaway: Hashing + frequency counting can replace sorting for better efficiency. Hashing patterns getting stronger day by day. 🔥 Day 52 done. #100DaysOfCode #LeetCode #DSA #Algorithms #HashMap #Strings #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 62/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Combination Sum Classic backtracking problem. Problem idea: Find all unique combinations where numbers sum up to a target. Each number can be used unlimited times. Key idea: Use backtracking (choose → explore → backtrack). Why? • We need to explore all possible combinations • Stop when sum exceeds target • Add result when sum == target How it works: • Pick a number • Stay on same index (reuse allowed) • Move forward when skipping • Backtrack to try other paths Time Complexity: Exponential (depends on combinations) Space Complexity: O(target) recursion depth Big takeaway: Backtracking is all about exploring choices and undoing them efficiently. This pattern is super important for recursion problems. 🔥 Day 62 done. #100DaysOfCode #LeetCode #DSA #Algorithms #Backtracking #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
📆 Day 8/30 of #30DaysofDSA Streak : 8/30 ✅ Problem : Number of 1 bits(LC #191) 🧠 problems was we have to convert decimal to binary and then count number of bits in that binary. Approach : firstly we need to convert decimal to binary and then reverse it because we have saved the remainders in reverse order then count the 1 bits using loop. Time Complexity -O(n) Space complexity - O(1) 💪 Key takeaways : - don't forget to reverse after adding bits in string. What approach would u use ?Drop in comments! #DSA #challenge #Leetcode #30DaysofDSA #Java #Data #Algorithms #DataStructures #Tech #LearningInPublic #100DaysOfCode #30DaysChallenge #CodingJourney
To view or add a comment, sign in
-
-
Day 43/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Search a 2D Matrix II Interesting matrix pattern here. Matrix properties: • Each row is sorted left → right • Each column is sorted top → bottom Key idea: Start from the top-right corner. Why? • If current value > target → move left • If current value < target → move down This way we eliminate one row or column every step. Time Complexity: O(m + n) Space Complexity: O(1) Big takeaway: Choosing the right starting point can simplify the entire search. Matrix patterns getting stronger day by day. 🔥 Day 43 done. #100DaysOfCode #LeetCode #DSA #Algorithms #Matrix #BinarySearch #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 68 of My DSA Journey Today’s problem: Symmetric Tree 🌳 Problem Statement Given a binary tree, check whether it is a mirror of itself (symmetric around its center). Key Insight A tree is symmetric if: Left subtree is a mirror of the right subtree Compare nodes in a cross manner: Left → Left with Right → Right Left → Right with Right → Left 🧠 Approach Use recursion to compare two nodes at a time Base cases: If both nodes are null → symmetric If one is null → not symmetric Check: Values are equal Outer and inner pairs match ⚡ Complexity Time: O(n) Space: O(h) (recursion stack) ✨ What I Learned This problem improved my understanding of recursion and how to think in terms of mirror structures instead of normal traversal. Consistency is the key 🔑 — one problem at a time! #DSA #Java #BinaryTree #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode | Day 47 🔍 Solved: Find Minimum in Rotated Sorted Array Today I explored another interesting variation of Binary Search. Instead of searching for a target, the goal was to find the minimum element in a rotated sorted array. 💡 Key Insight: By comparing the middle element with the last element, we can determine which half contains the minimum value. Approach: ✔ Used Binary Search to achieve O(log n) time complexity ✔ Compared mid with end to identify the unsorted portion ✔ Narrowed down the search space efficiently What I Learned: This problem helped me understand how binary search can be applied beyond simple searching—especially in rotated and partially sorted arrays. #Java #DSA #LeetCode #BinarySearch #CodingJourney #ProblemSolving #TechSkills
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