18/30 days ✅ Solved a LeetCode Problem #1342 — Number of Steps to Reduce a Number to Zero Successfully solved this problem in Java with 💯% runtime efficiency (0 ms)!The logic behind this problem is simple — we repeatedly perform operations to reduce a given number to zero while counting the steps. If the number is even, we divide it by two; if it is odd, we subtract one. This process continues until the number becomes zero, and the total number of operations gives the result. For example, for num = 14, the sequence is 14 → 7 → 6 → 3 → 2 → 1 → 0, which takes 6 steps. This approach efficiently reduces the number using basic conditional and looping logic, achieving a time complexity of O(log n). #LeetCode #CodingChallenge #JavaProgramming #ProblemSolving
Solved LeetCode Problem #1342 in Java with 0 ms runtime
More Relevant Posts
-
✨ Day 46 of 100: Simplify Path ✨ Today’s challenge was LeetCode 71 – Simplify Path 🧭 🧩 Problem Summary: Given an absolute path in a Unix-style file system, simplify it so that it represents the canonical path. We need to correctly handle ".", "..", and multiple slashes "/" while maintaining the correct directory structure. 💡 Key Takeaways: 🔹 Strengthened understanding of stack-based path traversal. 🔹 Learned how ".." can be used to move up directories and "." can be ignored. 🔹 Practiced string manipulation using split() and String.join() in Java. 🔹 Reinforced handling of edge cases like multiple consecutive slashes. 🧠 Core Idea: Use a Stack to keep track of valid directory names and rebuild the simplified path at the end. 💻 Language: Java ☕ #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingJourney #DSA #SimplifyPath #WomenWhoCode #CodingChallenge
To view or add a comment, sign in
-
-
🧩 Day 79 of #100DaysOfCode Today’s problem: LeetCode 3370 – Smallest Number With All Set Bits 💡 The challenge was to find the smallest number greater than or equal to n whose binary representation contains only set bits (1s). 💻 Language: Java ⚙️ Approach: Used bitwise operations to identify numbers whose binary form contains all 1s. The key condition used: (x & (x + 1)) == 0 This ensures that the number has all bits set. ✅ Result: Runtime – 0 ms, beating 100% of Java submissions! ⚡ 📈 Learning: This problem improved my understanding of bit manipulation and binary operations — core concepts for optimizing code performance. #Day79 #LeetCode #100DaysOfCode #CodingChallenge #JavaProgramming #ProblemSolving #BitManipulation #DeveloperJourney #CodeEveryday
To view or add a comment, sign in
-
-
23/30 days✅ Solved LeetCode Problem : #70 – Climbing Stairs The challenge was to determine how many distinct ways one can reach the top of a staircase with n steps, where at each step you can either climb 1 or 2 steps. The logic behind the problem is similar to the Fibonacci sequence, where each state depends on the sum of the previous two states. I implemented the solution in Java, using an iterative approach with three variables to optimize space complexity. Instead of using recursion or an array, the approach updates values in constant space (O(1)) while maintaining linear time complexity (O(n)). Here’s the logic in brief: Initialize a = 0, b = 1, and c = 1. For each step, compute c = a + b, then shift values forward (a = b, b = c). Return c as the total number of distinct ways to reach the top. #LeetCode #Java #DynamicProgramming #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 73 of #100DaysOfCode Today I solved LeetCode 3346 – Maximum Frequency of an Element After Performing Operations I 🧩 This problem was all about logical range manipulation — figuring out how many elements could be converted into the same number when each element can be modified by ±k, but with a limited number of allowed operations. At first, it felt similar to the “most frequent element” sliding window problem, but the twist here was controlling how many elements can be changed, not just the total cost. After a few failed attempts (and a battle with edge cases 😅), I finally implemented a correct solution using the difference array + prefix sum approach. 💡 Key Takeaways: Think in terms of ranges, not just differences. Prefix-sum (difference map) logic is incredibly powerful for interval counting. Always recheck constraints — “number of operations” vs “total cost” makes a huge difference! Here’s a snippet from my final Java solution: int achievable = Math.min(running, same + numOperations); ans = Math.max(ans, achievable); It’s small details like these that make problem-solving such a rewarding process 💪 #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #DSA #LearningEveryday
To view or add a comment, sign in
-
-
💡 LeetCode 3467 – Transform Array 💡 Today, I solved LeetCode Problem #3467: Transform Array, which focuses on array manipulation and the use of conditional logic in Java — a neat problem that strengthens core programming fundamentals. ⚙️ 🧩 Problem Overview: You’re given an integer array nums. Your task is to: Replace even numbers with 0 Replace odd numbers with 1 Then, sort the transformed array in ascending order. 👉 Example: Input → nums = [4, 7, 2, 9] Output → [0, 0, 1, 1] 💡 Approach: 1️⃣ Iterate through the array. 2️⃣ Use a ternary operator to transform each element (even → 0, odd → 1). 3️⃣ Sort the array to arrange all zeros before ones. ⚙️ Complexity Analysis: ✅ Time Complexity: O(n log n) — due to sorting. ✅ Space Complexity: O(1) — in-place transformation. ✨ Key Takeaways: Practiced logical thinking and ternary operations in Java. Strengthened understanding of array transformations and sorting. Reinforced the value of writing clean, concise, and efficient code. 🌱 Reflection: Even simple transformation problems like this one sharpen the habit of thinking algorithmically. Consistency in small challenges leads to big growth in problem-solving skills. 🚀 #LeetCode #3467 #Java #ArrayManipulation #LogicBuilding #ProblemSolving #CodingJourney #DSA #CleanCode #ConsistencyIsKey
To view or add a comment, sign in
-
-
📌 Day 10 of #45DaysOfLeetCode Challenge – Problem 2: Add Two Numbers (Medium)🚀 🔹Today’s problem tested my understanding of Linked Lists and carry-over logic in addition operations. 🔹The task was to add two numbers represented as linked lists where each node contains a single digit in reverse order — a neat way to simulate how we perform addition by hand! 🧠 Key Learnings: 🔹Handling edge cases when list lengths differ. 🔹Managing carry efficiently between node sums. 🔹Constructing a new linked list to store the result dynamically. 🔹Using a dummy head node to simplify list manipulation. 🚀 My solution achieved: ✅ Runtime: 1 ms (Beats 100%) ✅ Status: Accepted ✅ Language: Java 🔹This challenge reminded me that clarity in logic matters more than complex code — a small trick like using a dummy node can make your entire implementation cleaner and bug-free.🚀 🔗 Problem : https://lnkd.in/dCnS8iAh 😎 #Day10 #LeetCode #CodingChallenge #JavaDeveloper #DataStructures #LinkedList #ProblemSolving #CodeEveryday #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 95 of #100DaysOfCode 🧠 Solved "Fibonacci Number" in Java using a space-optimized iterative approach. 🔹 Problem: Given an integer n (0 ≤ n ≤ 30), compute the nth Fibonacci number where F(0)=0, F(1)=1 and F(n)=F(n-1)+F(n-2) for n>1. 🔹 Approach: • Handle base cases (n=0 or n=1). • Use two variables (prev=0, curr=1) and iterate from i=2 to n. • In each step compute next=prev+curr, then update prev=curr and curr=next. • Return curr as the result. 🔹 Key Learning: • Iterative dynamic programming with constant space is ideal when only the last two states are needed. • Avoid using full arrays when you don’t need all historical values. • Clear, readable, and efficient code works well in interviews and production alike. 🔹 Thanks to: • Dr Bharathi Raja N — Director of Training & Placement, Dhanalakshmi College of Engineering • Sreesairam V Sir — Mentor from Aptitude Guru Hem #DhanalakshmiCollegeOfEngineering #LeetCode #Java #100DaysOfCode #Day95 #DynamicProgramming #CodingJourney
To view or add a comment, sign in
-
-
📘 Day 10 – LeetCode Daily Challenge Today’s problem was “Remove Duplicates from Sorted Array II”, solved in Java. The challenge was to modify a sorted array in-place, ensuring that each unique element appears at most twice, while keeping the order of elements unchanged. This problem tests how efficiently we can handle arrays without using any extra space — just pure logic and pointer manipulation! 💡 Key Concepts I Worked On: 🔹 Understanding how to use two pointers to track positions and avoid unnecessary shifting. 🔹 Maintaining the relative order of elements while eliminating extra duplicates. 🔹 Implementing an O(1) space solution, proving how logic can replace extra memory usage. 💭 What I Learned: This exercise reinforced how powerful the two-pointer technique can be for array-based problems. It’s a pattern that not only saves memory but also simplifies traversal and manipulation — making the solution both clean and efficient. #Day9 #LeetCode #Java #ProblemSolving #DataStructures #Algorithms #CodingChallenge #TwoPointers #100DaysOfCode #LearningJourney #CodingConsistency
To view or add a comment, sign in
-
-
NeetCode 25 | LeetCode #239 | Sliding Window Maximum Implemented an efficient solution using a deque to track potential maximums within each window. A classic example of optimizing brute force with data structures — achieving O(n) time complexity. #NeetCode #LeetCode #Java #DSA #Deque #SlidingWindow #Algorithms #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
🔹 Day 39 – LeetCode Practice Problem: Perfect Number (LeetCode #507) 📌 Problem Statement: A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding itself. Return true if the given number is perfect, otherwise return false. ✅ My Approach (Java): Initialize sum = 0. Iterate from 1 to num / 2. For every divisor i such that num % i == 0, add it to sum. After the loop, if sum == num, it’s a perfect number. 📊 Complexity: Time Complexity: O(n/2) Space Complexity: O(1) ⚡ Submission Results: Accepted ✅ Runtime: 2108 ms Memory: 41.19 MB 💡 Reflection: This problem reinforced the importance of divisor-based iteration. While this brute-force solution works, optimizing divisor checks using square roots can greatly improve performance — a good next step for refinement! #LeetCode #ProblemSolving #Java #DSA #CodingPractice #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