🚀 Day 6 / 100 – LeetCode Challenge Today I solved Number of Steps to Reduce a Number to Zero on LeetCode. 🧠 Problem Idea: Given a number "num", reduce it to "0" using these rules: - If the number is even → divide it by 2 - If the number is odd → subtract 1 Count how many steps it takes until the number becomes "0". 💡 Key Learning - Practiced loops and conditions - Understood how to update variables inside a loop - Learned how small logical steps reduce a number efficiently 💻 Approach 1. Run a loop until the number becomes "0" 2. Check if the number is even or odd 3. Update the number according to the rule 4. Count each step 📈 Takeaway: Simple problems help build strong fundamentals in logic, loops, and problem-solving, which are essential for mastering DSA. 🔗 Problem: Number of Steps to Reduce a Number to Zero #LeetCode #100DaysOfCode #Java #DSA #CodingJourney #ProblemSolving
Number of Steps to Reduce a Number to Zero on LeetCode
More Relevant Posts
-
🚀 Day 52 — LeetCode Practice 🚀 Today’s focus was on understanding number properties and simplifying logic. ✅ Problem solved today: 🔹 Ugly Number 💡 Key learnings from today: • Learned that ugly numbers have only 2, 3, and 5 as prime factors • Understood how repeated division can simplify factor checking • Avoided unnecessary factor calculations by focusing only on valid primes • Practiced writing clean and simple conditional logic • Strengthened understanding of loops and number reduction techniques Initially, I thought of checking all possible factors, which made the logic messy. But then I realized I only need to divide the number by 2, 3, and 5 until it reduces. If the number becomes 1 → it’s an ugly number If it gets stuck → it’s not This problem taught me an important lesson: Not every problem needs complex logic — sometimes focusing on the right conditions is enough. Logical thinking. Simplicity. Clean execution. Step by step, getting better 💪 On to Day 53 🚀 #Day52 #DSA #LeetCode #ProblemSolving #Java #CodingJourney #Consistency #FutureEngineer
To view or add a comment, sign in
-
-
🚀 Day 16 of My LeetCode Journey Today, I solved LeetCode Problem #747 – Largest Number At Least Twice of Others. 🔍 Problem Summary: Given an array of integers, we need to find whether the largest element is at least twice as much as every other number. If yes, return its index; otherwise, return -1. 💡 Approach I Used: First, find the largest and second largest elements in the array. Then check if the largest element is at least twice the second largest. If yes, return the index of the largest element. 🧠 Key Learning: This problem improved my understanding of: Array traversal Maintaining multiple variables (max & second max) Writing optimized O(n) solutions 📈 Progress: Consistency is the key 🔑 — improving step by step every day. #LeetCode #DSA #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 63 of #LeetCode Practice Solved: Count Equal and Divisible Pairs in an Array (Easy) 🔹 Problem Summary: Given an array and an integer k, find the number of pairs (i, j) such that: • nums[i] == nums[j] • (i * j) is divisible by k 🔹 Approach: • Used two nested loops to check all pairs • Compared elements to find equal values • Checked if (i * j) % k == 0 • Counted valid pairs 🔹 Key Learning: Brute-force helps build a strong foundation and improves problem understanding before optimization. 💡 Consistency, patience, and small daily improvements lead to big results over time. #LeetCode #DSA #Java #CodingJourney #Consistency #KeepLearning
To view or add a comment, sign in
-
-
🚀 Day 58 — LeetCode Practice 🚀 Today’s problem: Shuffle String (LeetCode 1528) 💡 Key Learning: • Learned how to rearrange characters using index mapping • Understood how placing elements at correct positions simplifies the problem • Practiced writing clean and efficient O(n) solutions • Strengthened thinking for array + string manipulation 🧠 Approach in simple words: Instead of modifying the original string, create a new array and place each character at its correct index using the given indices. ✨ Takeaway: Sometimes the simplest idea — “put the element in its right place” — gives the most optimal solution. Consistency is the real game 💪 #Day58 #LeetCode #DSA #CodingJourney #Java #Consistency #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 17 of My LeetCode Journey 📌 Solved: LeetCode #11 – Container With Most Water Today’s problem was a great example of applying the Two Pointer Approach efficiently. 🔍 Problem Summary: Given an array of heights, find two lines that together with the x-axis form a container that holds the maximum amount of water. 💡 Approach Used: Started with two pointers at both ends Calculated area using: min(height[left], height[right]) × width Moved the pointer with smaller height to maximize area ⚡ Key Learning: Instead of checking all pairs (O(n²)), we can optimize to O(n) using the two-pointer technique. 🧠 Time Complexity: O(n) 📦 Space Complexity: O(1) 🔥 Consistency is the key — learning something new every day! #LeetCode #DSA #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 54 — LeetCode Practice 🚀 ✅ Problem Solved: Sort Array By Parity 💡 What I learned today: • Understood how to separate even and odd numbers efficiently • Practiced using an extra array to store results in order • Learned a simple two-pass approach: first evens, then odds • Realized how clean logic can make problems easier without complex tricks 📊 Approach: First loop → store all even numbers Second loop → store all odd numbers ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) Small problem, but great for strengthening array manipulation skills! 💪 #Day54 #LeetCode #DSA #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 25/100 – LeetCode DSA Challenge ✅ Problem Solved: Third Maximum Number Today’s problem focused on finding the third distinct maximum number in an array. If it doesn’t exist, we return the maximum number. 🔍 Key Learnings: • Importance of handling distinct values (duplicates ignored) • Efficient tracking of top 3 values without sorting • Achieving O(n) time complexity using a single pass • Better understanding of edge cases like negative numbers 💡 Approach: Instead of sorting (O(n log n)), I used three variables to track the first, second, and third maximum values while iterating through the array once. 📌 Example: Input: [2,2,3,1] Output: 1 🎯 This problem improved my thinking on optimization and clean logic building. #Day25 #100DaysOfCode #DSA #LeetCode #Java #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
LeetCode Challenge – Day 49 Today I solved the Linked List Cycle problem. Problem Insight: Given a linked list, determine whether it contains a cycle (loop). A cycle occurs when a node points back to a previous node instead of reaching null. Approach: Used Floyd’s Cycle Detection Algorithm (Tortoise and Hare) Maintained two pointers: Slow pointer moves one step at a time Fast pointer moves two steps at a time If a cycle exists, both pointers will eventually meet If not, the fast pointer will reach the end of the list Key Learning: Using two pointers with different speeds helps efficiently detect cycles without extra space. Complexity: Time: O(n) Space: O(1) Understanding pointer movement made this problem much easier to solve. #LeetCode #Java #DSA #CodingJourney
To view or add a comment, sign in
-
Continuing my DSA practice on LeetCode, today I worked on another hard problem. * Problem: Valid Number (65) * Approach: This problem is about validating whether a string represents a valid number, including integers, decimals, and scientific notation. I solved it by scanning the string once and keeping track of certain conditions using flags: seenDigit to check if we have encountered any digit. seenDot to ensure only one decimal point appears. seenE to track if an exponent (e or E) appears. digitAfterE to make sure digits exist after the exponent. While iterating through the string, I handled different cases such as digits, signs (+/-), decimal points, and exponent characters and updated the flags accordingly. * Key Learning: This problem helped me practice carefully handling multiple conditions while parsing strings, which is common in many real-world validation and parsing tasks. #LeetCode #DSA #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 65 #LeetCode Practice ✅ Problem Solved: Minimum Number Game 💡 What I learned today: • Importance of sorting before processing • Understood how to simulate a game step-by-step • Learned swapping elements in pairs efficiently • Improved thinking on pattern-based array problems 📊 Approach: • First, sort the array • Traverse the array in steps of 2 • Swap every pair of elements • Return the modified array 🧠 Key Insight: Sometimes problems look complex, but after sorting, a simple pattern (pair swapping) solves it easily. 🔥 Consistency is the key! Showing up every day is building my problem-solving mindset step by step. #Day65 #LeetCode #DSA #Java #CodingJourney #Consistency #Learning
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