🚀 Day 3/100 – LeetCode Challenge 🔍 Problem: Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be inserted to maintain the sorted order. 💡 Key Concepts Used: • Binary Search • Time Complexity Optimization – O(log n) • Efficient searching in sorted arrays 📚 What I Learned: • How binary search reduces search time significantly compared to linear search • Handling edge cases when the target element is not present • Determining the correct insertion index while maintaining sorted order hashtag #100DaysOfCode #LeetCode #Java #DataStructures #Algorithms #BinarySearch #CodingJourney #ProblemSolving
Binary Search in Sorted Arrays with Java
More Relevant Posts
-
Day 36/50 🚀 Solved “Valid Parentheses” today — a classic stack problem, but a great reminder that simple concepts can be powerful when applied correctly. 💡 Key takeaway: Using a stack makes it easy to track opening brackets and validate matching pairs efficiently. Every closing bracket should correspond to the most recent unmatched opening one — LIFO in action. ⚙️ What I focused on: Clean conditional checks Avoiding unnecessary complexity Writing readable, structured code 📈 Result: Accepted ✅ Optimized runtime & solid performance On to Day 37 🔥 #50DaysOfCode #DataStructures #Algorithms #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
Day 57 of #100DaysOfLeetCode Today’s problem focused on finding the minimum distance between a target element and a given index in an array. I solved it using a simple and efficient approach: Traversed the array once Checked for target occurrences Calculated distance using absolute difference Maintained the minimum value throughout Runtime: 0 ms (Beats 100%) Optimized space usage Key takeaway: Even straightforward iteration can lead to highly optimized solutions when combined with the right logic. #LeetCode #Java #DataStructures #Algorithms #100DaysOfCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
60-Day LeetCode Challenge – Day 43 Solved Check If Two String Arrays are Equivalent on LeetCode. 📌 Approach: Concatenated both string arrays into two strings and compared them using .equals(). 🧠 Learning: Reinforced how string building and comparison works, especially when data is split across arrays. ⚡ Complexity: • Time Complexity: O(n + m) • Space Complexity: O(n + m) Simple logic, but a clean reminder that breaking a problem down makes it easier to solve. #LeetCode #DSA #Java #Strings #Consistency #ProblemSolving #LeetCode60
To view or add a comment, sign in
-
-
🚀100 Days of Code Day-26 LeetCode Practice – Remove Duplicates from Sorted Array Solved a classic problem using the Two Pointer Technique 💡 📌 Problem: Given a sorted array, remove duplicates in-place and return the number of unique elements. 🔍 Key Idea: Since the array is sorted, duplicates are adjacent. Using two pointers helps efficiently overwrite duplicates without extra space. ⚡ Complexity: Time → O(n) Space → O(1) 💻 Clean and optimized approach makes this problem a great example of in-place array manipulation! #LeetCode #Java #DataStructures #CodingPractice #ProblemSolving #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
-
-
#Day77 of my second #100DaysOfCode Finally wrapped up binary search on 1D arrays, now moving to binary search on answers. DSA • Solved Sqrt(x) (LeetCode 69) — finding the integer square root of a number without using built-in functions – Brute: iterate until square exceeds target → O(n) – Optimal: binary search on answer space → O(log n) • Key idea: instead of searching an index, we search for the answer itself • Learned how to narrow down the range based on mid² comparison Nice shift in thinking — binary search feels much more powerful now. #DSA #BinarySearch #LeetCode #Algorithms #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟕𝟕 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on finding all elements that appear more than n/3 times in an array. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Majority Element II 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 – 𝐇𝐚𝐬𝐡𝐌𝐚𝐩 • Counted frequency of each element using a map • Calculated threshold = n / 3 • Collected elements whose frequency exceeded the threshold 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • At most 2 elements can appear more than n/3 times • HashMap is straightforward for frequency counting • Understanding constraints helps reduce possibilities • This problem has an optimized Boyer-Moore Voting (extended) solution 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(n) • Space: O(n) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Constraints often reveal hidden patterns — understanding them leads to better optimizations. 77 days consistent 🚀 On to Day 78. 🔗 Problem Link: https://lnkd.in/dDwdWYJs #DSA #Arrays #HashMap #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
#Day75 of my second #100DaysOfCode Today’s problem was more about spotting patterns than writing code. DSA • Solved Single Element in a Sorted Array (LeetCode 540, Medium) – Brute: linear scan checking pairs → O(n) – Optimal: binary search using index pattern → O(log n) • Key idea: elements appear in pairs, and the single element breaks this pattern • Used position-based logic to decide which half to search This one really showed how observing patterns can simplify the approach. #DSA #BinarySearch #LeetCode #Algorithms #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
-
Day 90 of #100DaysOfCode – Unique Binary Search Trees II Today’s problem was all about generating all structurally unique BSTs for values from 1 to n. At first glance, it feels tricky because it's not just counting trees — we actually need to build every possible tree structure. 💡 Key Insight: Pick each number i as the root Recursively build: Left subtree from [1 ... i-1] Right subtree from [i+1 ... n] Combine every left & right subtree pair 🌳 This is a classic Recursion + Backtracking problem and is closely related to Catalan Numbers. 📌 Example: For n = 3, we get 5 unique BSTs ⚡ What I learned today: How recursion can generate combinations of structures Importance of base case (start > end → null) Combining subproblems effectively 💻 Time Complexity: Approximately O(4ⁿ / √n) Consistency is key — 90 days strong and still going 💪 Next target: 💯 #DSA #Java #LeetCode #Recursion #BinaryTree #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
#Day76 of my second #100DaysOfCode Binary search continues to surprise me with how many variations it has. DSA • Solved Find Peak Element (LeetCode 162) – Brute: check every element → O(n) – Optimal: binary search based on slope comparison → O(log n) • Key idea: if the next element is greater, move right; else move left — a peak is guaranteed • Didn’t need to check all elements, just follow the increasing/decreasing trend Interesting how this doesn’t require a fully sorted array, yet binary search still works. #DSA #BinarySearch #LeetCode #Algorithms #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
Explore related topics
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