🚀 Day 40 of #100DaysOfDSA Solved LeetCode Problem #69 – Sqrt(x) 🧮 💡 Problem Insight: Given a non-negative integer x, return the square root of x rounded down to the nearest integer. For example: Input: x = 8 Output: 2 (since √8 ≈ 2.828, and floor(2.828) = 2) ✨ Key Learnings: Practiced binary search to find results efficiently without using built-in math functions. Learned how to narrow down search space based on mid-square comparisons. Reinforced understanding of integer division and rounding down behavior. Time Complexity: O(log n) — fast and efficient! Space Complexity: O(1) 💬 Lesson: Binary Search isn’t just for sorted arrays — it’s a mindset for narrowing down possibilities quickly 🚀 #LeetCode #Python #DSA #BinarySearch #ProblemSolving #100DaysOfCode #Day40 #CodingJourney
Solved LeetCode Problem #69 – Sqrt(x) using Binary Search
More Relevant Posts
-
🚀 LeetCode #1625: Lexicographically Smallest String After Applying Operations Today’s problem was about transforming a numeric string using two operations: adding a value to digits at odd indices and rotating the string, to get the lexicographically smallest result possible. The challenge was to handle infinite possibilities smartly. I used a Breadth First Search (BFS) approach to systematically explore all reachable string states while keeping track of visited ones. 💡 Key Takeaways: - Some problems don’t need a direct formula, they need systematic exploration. - BFS is not just for graphs; it’s a powerful tool for exploring state transitions too. - Modular arithmetic and rotation logic often come together in string manipulation problems. This one was a great reminder that clean logic and state tracking can solve even the most “infinite looking” problems efficiently. #LeetCode #ProblemSolving #Python #DSA #CodingChallenge #Algorithms #BFS #StringManipulation #LearningEveryday
To view or add a comment, sign in
-
-
🧩 Day 54 of #LeetCode365 Problem: 69. Sqrt(x) Category: Binary Search | Math Today’s problem was all about finding square roots… but without using math.sqrt() 😤 — because that’s too easy, right? So I made my own version using binary search. Basically, I played “guess the root” until my code said, “close enough, stop now.” 😎 💻 Approach: 👉 Set l = 0, r = x 👉 Use binary search to narrow down the integer part of √x 👉 Return the best guess (a.k.a. the floor of the real answer) ⚙️ Complexity: ⏱ O(log n) | 💾 O(1) 💡 Lesson: Sometimes you don’t need to know the exact answer — just the closest one that doesn’t crash your code 🤷♂️ #LeetCode #Python #CodingHumor #DSA #BinarySearch #ProgrammerHumor
To view or add a comment, sign in
-
-
🔍 Day 44 DSA Challenge – Problem #33: Search in Rotated Sorted Array 📌 Problem Statement: Given a sorted array nums that may have been rotated at an unknown pivot, find the index of a target value. Return -1 if the target doesn’t exist. The solution must run in O(log n) time. ⚙️ How I Solved It: Applied a modified binary search: Identify which half (left or right) is sorted. Narrow the search to the half where the target could exist. Repeat until the target is found or search space is exhausted. 📊 Performance Stats: ⏱ Runtime: 0 ms (⚡ beats 100%) 💾 Memory: 12.65 MB (beats 42.49%) ✅ Testcases Passed: 196 / 196 🧠 Key Takeaway: Understanding array properties like rotation and leveraging binary search ensures optimal search performance in logarithmic time. #LeetCode #BinarySearch #RotatedArray #Problem33 #Python #DSA #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
#96day of #100DaysOfCode 🌱 LeetCode 109: Convert Sorted List to Binary Search Tree Today’s challenge was about building balance — literally! Given a sorted linked list, we need to convert it into a height-balanced BST 🌳 🧠 Key Idea: The middle element of the list becomes the root. Left half forms the left subtree, right half forms the right subtree. Use slow–fast pointers to find the middle efficiently. 📈 Complexity: Time: O(n log n) Space: O(log n) (recursion stack) 💬 Learning: Balance matters — in trees, in code, and in life 🌿 Sometimes, the middle point creates the strongest foundation. #LeetCode #DSA #BinarySearchTree #LinkedList #CodingChallenge #Python #Algorithm #LeetCodeDaily #100DaysOfCode
To view or add a comment, sign in
-
-
Day 66: Find Minimum in Rotated Sorted Array II 📉 (Simple Version) I'm tackling an advanced Binary Search problem on Day 66 of #100DaysOfCode: "Find Minimum in Rotated Sorted Array II." The challenge is to find the minimum element in a rotated sorted array that may contain duplicates. My solution uses a modified Binary Search approach. The key difficulty is when the middle element (nums[mid]) equals the rightmost element (nums[right]). In this case, we can't tell if the minimum is on the left or the right. To resolve this ambiguity, I simply discard the rightmost element by setting right -= 1. This adjustment keeps the search on track, achieving an optimal O(log n) complexity in the typical case. My solution achieved 100% runtime efficiency! #Python #DSA #Algorithms #BinarySearch #Arrays #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 37 of #100DaysOfDSA Solved LeetCode Problem #13 – Roman to Integer 🏛️➡️🔢 📌 Problem Insight: The challenge is to convert a Roman numeral string into an integer. Roman numerals use combinations of letters like I, V, X, L, C, D, M — but with a twist: when a smaller value appears before a larger one, it must be subtracted. 💡 Key Learnings: Practiced mapping characters to values using dictionaries. Strengthened understanding of conditional logic in sequential traversal. Reinforced use of iteration and subtraction patterns. Time complexity: O(n) Space complexity: O(1) 📌 Approach (short): Store Roman symbol values in a dictionary. Traverse the string from left to right. If a smaller numeral comes before a larger one → subtract it; else → add it. 👉 Every small problem adds up to strong logic — step by step, symbol by symbol 💪 #LeetCode #DSA #ProblemSolving #100DaysChallenge #Day37 #Python #CodingJourney #RomanToInteger #LogicBuilding
To view or add a comment, sign in
-
-
🗓 Day 13 / 100 – #100DaysOfLeetCode 📌 Problem 1513: Number of Substrings With Only 1s The task was to count how many substrings in a binary string consist only of consecutive 1s. 🧠 My Approach: Identified continuous blocks of '1' in the string. For each block of length k, calculated the number of valid substrings using the formula: k × (k + 1) / 2 Summed these counts across all segments of consecutive 1s. This avoids checking all substrings individually and keeps the solution efficient and clean. 💡 Key Learning: This problem reinforces the value of recognizing sequences and using mathematical formulas to simplify substring counting. It’s a reminder that many problems can be solved much faster when we look for structure instead of brute force. One more problem, one more pattern learned 🚀 #100DaysOfLeetCode #LeetCodeChallenge #Python #ProblemSolving #Strings #Algorithms #MathInCoding #LogicBuilding #DataStructures #DSA #CompetitiveProgramming #CodingJourney #SoftwareEngineering #LearningInPublic #DeveloperJourney #TechStudent #CareerGrowth #CodeEveryday #CodingCommunity #KeepLearning
To view or add a comment, sign in
-
-
🧩 Day 42 — Add Digits (LeetCode 258) 📝 Problem Given an integer num, repeatedly add all its digits until the result has only one digit, and return it. 🔁 Approach -Continuously sum the digits of the number until a single-digit result remains. -Alternatively, use the digital root formula: -If num == 0, return 0. -Else, return 1 + (num - 1) % 9. 📊 Complexity -Time Complexity: O(1) -Space Complexity: O(1) 🔑 Concepts Practiced -Mathematical optimization -Modulo operation -Digital root pattern #Leetcode #python #DSA #ProblemSolving #Math #Optimization
To view or add a comment, sign in
-
-
Day 30 / 100 – Majority Element II (LeetCode #229) Today’s challenge was all about identifying numbers that appear more than ⌊ n/3 ⌋ times in an array. This problem was a great way to explore the Boyer–Moore Voting Algorithm, an elegant and efficient method to find potential majority elements without using extra space. 🔍 Key Learnings Understanding how counters and candidates evolve in an iterative approach Strengthening logic for pattern recognition and frequency analysis Realizing how efficient algorithms can reduce time and memory usage 💭 Thought of the Day Consistency isn’t just about showing up — it’s about learning smarter each day. Every new problem isn’t a repetition; it’s a refinement of logic and discipline. 🔗 Problem Link:https://lnkd.in/gfiGVueC #100DaysOfCode #Day30 #LeetCode #Python #ProblemSolving #CodingChallenge #DataStructures #Algorithms #LearningJourney #CodeEveryday #TechGrowth
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