🎉 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
Reducing a Number to Zero with Recursion on LeetCode
More Relevant Posts
-
🎉 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 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
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 54 – 100 Days Coding Challenge 📌 Problem: Three Sum ⚙️ Approach • First, sort the array to make it easier to apply the two-pointer technique • Iterate through the array and fix one element at a time • For each fixed element, use two pointers (left and right) to find pairs whose sum equals the negative of the fixed element • Skip duplicate elements to avoid repeating triplets • Move pointers based on the sum: – If sum == 0 → store the triplet and move both pointers – If sum < 0 → move left pointer forward – If sum > 0 → move right pointer backward 🧠 Logic Used • Sorting + Two Pointer Technique • Handling duplicates efficiently to ensure unique triplets • Reducing time complexity from brute force O(n³) to O(n²) 🔗 GitHub: https://lnkd.in/g_3x55n8 ✅ Day 54 Completed #100DaysOfCode #Java #DSA #ProblemSolving #Algorithms #DataStructures #LeetCode #CodingPractice #TwoPointers #ArrayProblems
To view or add a comment, sign in
-
-
🚀 Day 25/100 – #100DaysOfCode | Mini Project Upgrade Today I improved my Student Marksheet Generator by adding a real-world rule 💻 •if a student scores less than 30 in any subject, the result will be Fail, regardless of the overall percentage. 📌 Features of the project: • Takes user input (name & roll number) • Accepts marks for 5 subjects • Calculates total and percentage •if a student scores less than 30 in any subject, the result will be Fail, regardless of the overall percentage. • Assigns grade automatically (A+, A, B, C, Fail) • Displays a structured marksheet 💡 What I learned: • Implementing real-world conditions in code • Improving existing logic step by step • Writing cleaner and more meaningful programs 🎥 Sharing a short demo video of the program in action. 📈 Learning, improving, and building consistency every day 🚀 #100DaysOfCode #Java #MiniProject #CodingJourney #LearningInPublic #DeveloperJourney #Consistency #BuildInPublic
To view or add a comment, sign in
-
Building strong fundamentals, one concept at a time 💡 Understanding the true power of Java — from platform independence to portability — and how “Write Once, Run Anywhere” makes it a game-changer in the programming world. This journey is not just about coding, but about thinking, solving, and growing every day 🚀 #Java #TapAcademy #LearningJourney #Programming #FutureEngineer #TechSkills
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 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 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
-
-
Excited to share my first C++ project – Simple Calculator! 💻 Here is the code for a basic calculator that performs: ✔ Addition ✔ Subtraction ✔ Multiplication ✔ Division 📌 Logic: Takes two numbers and an operator as input Uses switch-case to perform operations Displays result based on user input 🔗 Code attached / GitHub link in comments I am continuously learning and improving my coding skills. 💡 Feedback is welcome! #cpp #coding #github #beginners #learningjourney
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