🎉 Day 8 of My 100-Day Programming Challenge! 🚀 Today, I solved the “Sqrt(x)” problem on LeetCode. The task is to compute the square root of a non-negative integer and return the result rounded down to the nearest integer, without using built-in functions like pow() or sqrt(). 🧩 🔍 Approach: I used the Binary Search technique to efficiently find the square root. ⚙️ Steps: • Define the search space from 1 to x. • Calculate the middle value (mid). • Check if mid * mid is equal to x. • If less than x, move right and store the potential answer. • If greater than x, move left. • Continue until the search space is exhausted. 💡 Key Insights: ✔ Binary Search reduces time complexity significantly. ✔ Avoids overflow using mid <= x / mid instead of mid * mid. ✔ Efficient way to compute roots without built-in functions. 🧠 Complexity: • Time Complexity: O(log n) • Space Complexity: O(1) Another great problem to strengthen Binary Search fundamentals and mathematical problem-solving skills. On to the next challenge! 💻🔥 #100DaysOfCode #Java #LeetCode #DSA #BinarySearch #Programming #CodingChallenge
Computing Sqrt(x) with Binary Search on LeetCode
More Relevant Posts
-
🎉 Day 9 of My 100-Day Programming Challenge! 🚀 Today, I solved the “Number of Steps to Reduce a Number to Zero” problem on LeetCode. The task is simple yet interesting — reduce a number to zero by applying the following rules: • If the number is even → divide it by 2 • If the number is odd → subtract 1 🔍 Approach: I used a recursive approach to repeatedly apply the rules until the number becomes zero, while counting the number of steps taken. ⚙️ Steps: • Check if the number is zero → return steps • If even → divide by 2 and increment steps • If odd → subtract 1 and increment steps • Continue recursively until reaching zero 💡 Key Insights: ✔ Demonstrates the concept of recursion and base condition ✔ Simple logic but helps build strong fundamentals ✔ Can also be solved iteratively for better space optimization 🧠 Complexity: • Time Complexity: O(log n) • Space Complexity: O(log n) (due to recursion stack) Another great problem to strengthen problem-solving and recursion skills. Consistency is key — onto Day 10! 💻🔥 #100DaysOfCode #Java #LeetCode #DSA #Recursion #Programming #CodingChallenge
To view or add a comment, sign in
-
-
🎉 Day 13 of My 100-Day Programming Challenge! 🚀 Today, I solved the “Minimum Absolute Distance Between Mirror Pairs” problem on LeetCode. The goal is to find the minimum index distance between pairs where one number is the reverse of the other. 🧩 🔍 Approach: I used a HashMap + number reversal technique to efficiently track and compare mirror pairs. ⚙️ Steps: • Traverse the array from left to right • Reverse the current number • Check if the current number already exists in the map • If yes → calculate distance using i - previousIndex • Store the reversed number in the map for future matches 💡 Key Insights: ✔ Reversing numbers helps identify mirror pairs quickly ✔ HashMap enables O(1) lookup for efficient comparison ✔ Single pass solution makes it optimal 🧠 Complexity: • Time Complexity: O(n × d) (d = number of digits) • Space Complexity: O(n) A great problem to strengthen concepts in Hashing, Number Manipulation, and Optimization. Consistency continues — let’s keep building! 💻🔥 #100DaysOfCode #Java #LeetCode #DSA #HashMap #Programming #CodingChallenge
To view or add a comment, sign in
-
-
Day 60 of My 90-Day Coding Challenge Today I worked on a classic recursion + backtracking problem — and it really tested how well I understand breaking problems into smaller decisions. At first, it feels messy: multiple partitions, multiple choices, and many possible paths. But once you start thinking in terms of: -“Try every possible cut and validate it” the structure becomes clear. Key learning: • Recursion is about exploring all paths, not rushing to the answer • Validity checks (like palindrome here) are what control the tree • Clean backtracking (add → recurse → remove) is everything One thing that really helped today: Even if you don’t know where to start, just begin drawing the recursion tree. As you expand it step by step, the logic starts revealing itself — what choices to make, when to stop, and how to backtrack. What stood out today: Clarity in recursion doesn’t come from memorizing patterns — it comes from visualizing the process. Still improving. #90DaysOfCode #DSA #Java #Recursion #Backtracking #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 568 of #750DaysOfCode 🚀 🔍 Problem Solved: Two Furthest Houses With Different Colors Today’s problem looked simple at first, but it had a nice twist that tested observation skills more than brute force thinking. 💡 Key Insight: To maximize the distance between two houses with different colors, we don’t need to check all pairs. The answer will always involve either: the first house, or the last house Why? Because the maximum distance comes from the edges of the array. ⚡ Approach: Compare every house with the first and last house If colors are different → calculate distance Keep track of the maximum distance 🧠 Optimization: Instead of an O(n²) brute-force approach, we can solve this in O(n) time with constant space. 📈 Complexity: Time: O(n) Space: O(1) ✨ Takeaway: Sometimes the best solution isn’t about trying everything — it’s about spotting the right pattern. #LeetCode #Java #DSA #CodingJourney #ProblemSolving #100DaysOfCode #Programming #Tech #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 89 — LeetCode Practice 🚀 Today’s focus was on array traversal and conditional counting. ✅ Problem solved today: 🔹 LeetCode — 2798. Number of Employees Who Met the Target 💡 Key learnings from today: • Practiced iterating through arrays using loops • Strengthened understanding of conditional statements (if) • Learned how to count values that satisfy a given condition • Improved problem-solving with a simple and efficient approach • Reinforced basics of time complexity — O(n) 🧠 Approach used: Loop through the hours array, check if each employee’s hours are greater than or equal to the target, and increment the count. Small problem — but solid practice on fundamentals that matter in coding interviews. #Day89 #LeetCode #Java #DSA #CodingJourney #ProblemSolving #Programming #LearningEveryday #ConsistencyWins
To view or add a comment, sign in
-
-
🚀 Days 64-100 #100DaysLeetCodeChallenge Completed! 🎉 What started as a small daily commitment turned into one of the most disciplined journeys of my learning phase. Solving problems consistently helped me improve my problem-solving skills, logic building, and confidence in coding Here are some of the problems I worked on recently: 🔹 Array-based pattern problems (peaks, rotations, and sequences) 🔹 Matrix-based challenges involving counting and traversal 🔹 Searching and sorting-based problems 🔹 Linked List manipulations and edge case handling 🔹 Classic algorithmic problems like sum combinations and unique elements Key Takeaways: Consistency > Motivation Practice makes patterns visible Mistakes are the best teachers #100DaysOfCode #LeetCode #DSA #CodingJourney #Consistency #Learning #Java
To view or add a comment, sign in
-
Day 5 / 100 Days of Coding : Solved: Best Time to Buy and Sell Stock Today’s problem looked simple but taught a powerful concept — tracking minimums and maximizing profit in a single pass. Key Learning: Instead of checking all pairs (which is slow), we maintain: Minimum price so far Maximum profit so far This reduces complexity from O(n²) → O(n) Consistency is the real game. Showing up every day matters more than perfection. #100DaysOfCode #DSA #LeetCode #Java #CodingJourney #ProblemSolving #GreedyAlgorithm
To view or add a comment, sign in
-
-
Day 53 of #100DaysOfCode Didn’t post after Day 7… not because I stopped — but because I got deeper into the process. Some problems don’t take hours, they take days. And honestly, that’s where the real growth happens. So far: ✔️ 25 problems solved ✔️ Countless hours of thinking, debugging, and rethinking One thing I’ve realized (something not many people talk about): Most DSA questions aren’t about knowing the solution — they’re about recognizing the *pattern*. But here’s the catch— The same pattern can appear in completely different forms, and unless you’ve struggled with it before, you won’t even recognize it. That’s why sometimes a single question can take 2–3 days — not because it’s “hard”, but because it’s *teaching you how to think*. I’ve started noticing: • Many problems are just variations of a few core ideas (two pointers, sliding window, hashing, recursion) • The difficulty lies in identifying *which lens to use* Still learning. Still showing up. Consistency isn’t loud — it’s quiet and repetitive. On to Day 100 💪 #DSA #LeetCode #Consistency #ProblemSolving #Java
To view or add a comment, sign in
-
-
🚀 Day 15 of 180 — 3Sum Closest ✅ LeetCode 16 — 3Sum Closest First sort the array. Then fix one element and use two pointers for the remaining two — one at left, one at right. For every triplet I calculate the sum and check how far it is from the target: distance = |target - sum| If this distance is less than my current minimum difference, I update my answer. Moving pointers is simple — if sum is greater than target → move right pointer left if sum is less than target → move left pointer right if sum equals target → that's the closest it can get, return immediately The key thing I made sure — keep tracking the minimum difference throughout and update result whenever a closer sum is found. Day 15 done. 165 to go. 🔥 #180DaysDSA #Day15 #LeetCode #Java #DSA #TwoPointers #Sorting #ThreeSum #DSAJourney #CodingJourney #Programming #DataStructures #Algorithms #ProblemSolving #BuildInPublic #CodeNewbie #LearnToCode #100DaysOfCode #SoftwareDevelopment #Developer #StudentDeveloper #TechCommunity #LinkedInTech #CompetitiveProgramming
To view or add a comment, sign in
-
-
🚀 Day 13 / 50 – Wild Coding Kickoff 🔥 Today’s problem looked like it wanted a complicated solution… but it ended up teaching me something much simpler. I read the question and instantly thought: “Okay, substring search… this might get tricky.” 👀 Loops, comparisons, edge cases… my mind started going there. But then I stopped and asked: 👉 “Is there a simpler way?” That’s when I used this: class Solution { public int strStr(String haystack, String needle) { int index = haystack.indexOf(needle); return index; } } 💡 What does indexOf() actually do? It searches for the first occurrence of needle inside haystack Returns: ✅ The starting index if found ❌ -1 if the substring is not present 🔥 Example haystack = "sadbutsad" needle = "sad" 👉 Output: 0 (because "sad" starts at index 0) 🧠 What I learned today Sometimes we try to prove we know everything… But real skill is knowing when to keep things simple. Using built-in methods effectively is also a skill. #Day13 #50DaysOfCode #WildCodingKickoff #LeetCode #Java #CodingJourney #Consistency #KeepItSimple #ProblemSolving
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