Day 10.2 of Java with DSA Journey 🚀 📌 Problem: Base 7 Conversion (LeetCode 504) At first, this looks like a simple math problem… But it actually teaches something deeper: 👉 How numbers are built in different systems 💡 Core Idea To convert a number from base 10 → base 7: Divide by 7 Store remainder Repeat until 0 Reverse the result 🧠 Key Learnings 🔹 Understanding Number Systems Decimal (base 10) is just one system—this logic works for ANY base 🔹 Modulo + Division Pattern num % base → current digit num / base → move to next position 🔹 Why Reverse? We generate digits from least significant → most significant ⚡ Complexity ⏱ Time: O(log₇ n) 📦 Space: O(log₇ n) 🔥 Pro Tips (Interview Level) 💡 Tip 1: This is a Universal Pattern This exact logic works for: Binary (base 2) Octal (base 8) Hex (base 16) 👉 Learn once, apply everywhere. 💡 Tip 2: Handle Negatives Separately Always convert using abs(num) and attach - later This avoids tricky modulo behavior. 💡 Tip 3: Avoid String Concatenation in Loops Use StringBuilder 👉 Shows awareness of time complexity + memory efficiency 💡 Tip 4: Reverse Thinking = Interview Gold If you're building output backward → think reverse at the end 💡 Tip 5: Hidden Optimization Insight If allowed, you could also: Use recursion → cleaner logic Or pre-calculate size for optimization 🔥 Real Insight This problem is not about Base 7… It’s about understanding: 👉 How computers represent and transform numbers internally Once you master this, you can convert between any number systems. Consistency builds depth 📈 #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Algorithms #MathLogic #Day10 #BitManipulation #InterviewPrep #CleanCode #Array #Optimization #MCA #lnct #100DaysOfCode #SoftwareEngineering #Algorithms #InPlaceAlgorithms #TechLearning #JavaDeveloper
Ashish Tiwari’s Post
More Relevant Posts
-
🚀 Day 11.3 of Java DSA Journey —The Problem That Starts Everything 🧠 📌 Problem: Fibonacci Number (LeetCode 509) Most people learn Fibonacci as a simple sequence… But today I realized: 👉 It’s the foundation of Dynamic Programming 💡 Core Idea Each number depends on the previous two: 👉 F(n) = F(n-1) + F(n-2) Simple formula. Powerful concept. 🧠 Key Learnings 🔹 Recursion vs Iteration Recursion is intuitive… but inefficient 🔹 Avoid Recalculation Naive recursion → O(2ⁿ) time ❌ Iterative approach → O(n) time ✅ 🔹 Space Optimization No need for arrays — just 2 variables ⚡ Complexity ⏱ Time: O(n) 📦 Space: O(1) 🔥 Pro Tips (Interview Level) 💡 Tip 1: Recognize Overlapping Subproblems If the same values are recomputed → think DP 💡 Tip 2: Start with Base Cases F(0) = 0, F(1) = 1 → everything builds from here 💡 Tip 3: Optimize Space Early If you only need last 2 values → don’t store everything 💡 Tip 4: Think Bottom-Up Iteration often beats recursion in interviews 💡 Tip 5: This Pattern Repeats Everywhere Fibonacci appears in: 1.Climbing Stairs 2.DP problems 3.Optimization challenges 🔥 Real Insight This problem taught me: ❌ Don’t just follow recursion blindly ✅ Understand the cost of recomputation That’s the difference between: 👉 Writing code 👉 Designing efficient solutions Consistency builds systems 📈 #DSA #LeetCode #Java #CodingJourney #DynamicProgramming #ProblemSolving #InterviewPrep #Day11 #BitManipulation #InterviewPrep #CleanCode #Array #Optimization #MCA #lnct #100DaysOfCode #SoftwareEngineering #Algorithms #InPlaceAlgorithms #TechLearning #JavaDeveloper
To view or add a comment, sign in
-
Day 9.2 of Java with DSA Journey 🚀 📌 Problem: Number of Steps to Reduce a Number to Zero (LeetCode 1342) At first glance, this looks too easy… But hidden inside is a powerful idea: 👉 Thinking in binary instead of decimal 💡 Core Idea Keep reducing the number until it becomes 0: Even → divide by 2 Odd → subtract 1 Simple rule. Powerful pattern. 🧠 Key Learnings 🔹 Iterative Thinking Used a loop to repeatedly transform the state 🔹 Decision Making per Step Even vs Odd → determines next move 🔹 Bitwise Insight num % 2 == 0 → (num & 1) == 0 num / 2 → num >> 1 ⚡ Complexity ⏱ Time: O(log n) 📦 Space: O(1) 🔥 Pro Tips (Interview Level) 💡 Tip 1: Think in Binary, Not Decimal Every division by 2 removes one bit → that's why complexity is logarithmic. 💡 Tip 2: Count Operations Without Simulation Steps = 👉 (Number of bits - 1) + (Number of 1s in binary) Example: 14 → 1110 Steps = (4 - 1) + 3 = 6 💡 Tip 3: Bitwise > Arithmetic (When Optimizing) Replace: % 2 → & 1 / 2 → >> 1 This shows low-level understanding. 💡 Tip 4: Pattern Recognition Matters This problem is not about loops… It’s about recognizing bit reduction patterns. 💡 Tip 5: Always Look for Hidden Math Even simple problems often have a mathematical shortcut behind them. 🔥 Real Insight This problem teaches a subtle shift: ❌ “Keep applying rules” ✅ “Understand what each operation does to the binary structure” That’s how you move from coding → engineering. Consistency compounds 📈 #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Day9 #BitManipulation #InterviewPrep #CleanCode #Array #Optimization #MCA #lnct #100DaysOfCode #SoftwareEngineering #Algorithms #InPlaceAlgorithms #TechLearning #JavaDeveloper
To view or add a comment, sign in
-
-
Day 3 of Java with DSA Journey 🚀 📌 Topic: Guess Number Higher or Lower (LeetCode 374) 💬 Quote: "Efficiency is not about doing more; it's about eliminating what doesn't matter." ✨ What I Learned: 🔹 Binary Search Beyond Arrays: Binary Search isn’t limited to arrays — it works perfectly on a number range like [1...n]. 🔹 Working with APIs: Learned how to adapt logic based on API responses: -1 → Guess is too high 1 → Guess is too low 0 → Correct answer 🔹 Power of Efficiency: Even for a huge range (up to 2³¹ - 1), Binary Search finds the answer in ~31 steps 🤯 Compared to Linear Search → practically impossible! 🔹 Complexity: ⏱ Time: O(log n) 📦 Space: O(1) 🧠 Problem Solved: ✔️ Guess Number Higher or Lower 💡 Key Insight: This problem highlights the “Narrowing the Search Space” concept. Each step eliminates half the possibilities — that’s the magic of logarithmic algorithms ⚡ ⚡ Interview Insight (3-Way Decision Logic): Unlike boundary problems, here we deal with three outcomes: 1️⃣ 0 → Found the number (return immediately) 2️⃣ -1 → Move right = mid - 1 3️⃣ 1 → Move left = mid + 1 👉 Use while (left <= right) since the target is guaranteed to exist. 🔑 Takeaway: Consistency beats intensity. Showing up daily is what builds mastery. #DSA #LeetCode #Java #CodingJourney #BinarySearch #ProblemSolving #100DaysOfCode #JavaDeveloper #Algorithms
To view or add a comment, sign in
-
-
Day 10 of Java DSA Journey 🚀 📌 Problem: Power of Two (LeetCode 231) Most people solve this using loops: ➡️ Keep dividing by 2 until you reach 1 But today I learned something better: 👉 You can solve it in ONE line using bit manipulation 🤯 💡 Core Idea A number is a power of two if: ✔️ It has only one ‘1’ in its binary form Examples: 1 → 0001 2 → 0010 4 → 0100 16 → 10000 🧠 The Magic Trick 👉 n & (n - 1) This removes the rightmost set bit So: If result = 0 → only one bit was set → ✅ Power of Two Else → ❌ Not a power of two ⚡ Complexity ⏱ Time: O(1) 📦 Space: O(1) 🔥 Pro Tips (Interview Level) 💡 Tip 1: Always Check Positivity First n > 0 is mandatory — bit tricks fail for negative numbers. 💡 Tip 2: Understand, Don’t Memorize n - 1 flips: the rightmost 1 → 0 all bits after it → 1 That’s why the trick works. 💡 Tip 3: This Pattern Appears Everywhere The same trick is used in: Counting set bits Subset generation Low-level optimizations 👉 Learn it once, reuse forever. 💡 Tip 4: Alternative Trick (Even Cleaner) Another way: 👉 (n & -n) == n This isolates the lowest set bit. If it's equal to n, only one bit exists. 💡 Tip 5: Bitwise = Senior-Level Thinking Using bit manipulation shows: ✔️ You understand how data is stored ✔️ You can optimize beyond brute force 🔥 Real Insight This problem is not about checking powers… It’s about recognizing: 👉 Patterns in binary representation Once you see that, the solution becomes obvious. Consistency builds mastery 🔑 #DSA #LeetCode #Java #BitManipulation #CodingJourney #ProblemSolving #InterviewPrep #Day10 #BitManipulation #InterviewPrep #CleanCode #Array #Optimization #MCA #lnct #100DaysOfCode #SoftwareEngineering #Algorithms #InPlaceAlgorithms #TechLearning #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 Day 2 of Java with DSA Journey 📌 Topic: First Bad Version (LeetCode 278) 💬 Quote of the Day: "Binary Search isn't just an algorithm; it's a mindset of elimination over inspection." ✨ What I learned: 🔹 Beyond Arrays: Binary Search works on any monotonic search space—not just arrays 🔹 Boundary Thinking: Focus shifted from finding a value to identifying the first occurrence of a condition 🔹 Implementation: Used left < right to precisely converge on the boundary 🔹 Time Complexity: O(log n) | Space Complexity: O(1) 🔹 Common Mistake: Using right = mid - 1 and skipping the correct answer 🔹 Real-World Use: Debugging systems, version control tools (like finding breaking commits) 🔹 Optimization: Reduced expensive API calls by halving the search space 🔹 Alternative Approach: Linear scan (O(n)) but inefficient 🧠 Problem Solved: ✔️ First Bad Version 💡 Insight: Binary Search is not just about searching—it’s about identifying boundaries efficiently. This shift in thinking is crucial for solving real interview problems. ⚡ Interview Insight: If mid is bad, it might be the first bad version → so we keep it: 👉 right = mid (NOT mid - 1) This small detail makes a huge difference in correctness. Consistency is the real key 🔑 #DSA #LeetCode #Java #CodingJourney #BinarySearch #ProblemSolving #Day2 #SoftwareEngineering #MCA #lnct
To view or add a comment, sign in
-
-
🚀 Day 1 of Java with DSA Journey 📌 Topic: Binary Search (LeetCode 704) 💬 “Today I practiced a very fundamental problem from LeetCode.” Today was all about efficiency and smart problem solving. While Linear Search checks every element one by one, Binary Search drastically reduces the search space by half in each step — making it one of the most powerful techniques in DSA. ✨ What I Learned: 🔹 Divide & Conquer: Reducing the problem size at every step leads to faster solutions 🔹 Prerequisite: Works only on sorted arrays 🔹 Implementation: Used iterative approach with two pointers (low & high) 🔹 Time Complexity: O(log n) | Space Complexity: O(1) 🔹 Common Mistake: Wrong mid calculation or improper pointer updates causing infinite loops 🔹 Real-World Use: Search engines, databases, efficient lookup systems 🔹 Optimization Insight: Much faster than Linear Search (O(n)) for large datasets 💡 Pro Tip (Java Developers): Always calculate mid like this: mid = low + (high - low) / 2; 👉 Prevents integer overflow and makes your code production-ready. 🧠 Performance Insight: ✔️ Linear Search: If you have 1 million elements, you might check 1 million times. ✔️ Binary Search: For that same 1 million elements, you only need 20 checks max. That’s the power of optimization ⚡ 💡 Insight: Understanding how to reduce problem size is the key to writing efficient algorithms. Even the simplest problems build the strongest foundation. Consistency is the real key 🔑 #DSA #Java #LeetCode #CodingJourney #BinarySearch #ProblemSolving #SoftwareEngineering #Day1
To view or add a comment, sign in
-
-
Day 7.2 of Java with DSA Journey 🚀 📌 Topic: Find All Numbers Disappeared in an Array (LeetCode 448) Quote: "Constraints are not limitations—they are invitations to think smarter." ✨ What I learned today: 🔹 In-Place Hashing (Pro Trick): When extra space is restricted, the input array itself can act like a HashMap. 🔹 Index Mapping Insight: Since values are in range [1, n], each number maps to an index: 👉 index = value - 1 🔹 Sign Flipping Technique: Mark elements as “visited” by flipping the value at the mapped index to negative. ✔️ Negative → already seen ✔️ Positive → missing number 🔹 Efficiency: ✔️ Time Complexity: O(n) ✔️ Space Complexity: O(1) (No extra data structures used!) 🧠 Problem Solved: ✔️ Find All Numbers Disappeared in an Array 💡 Key Insight: This problem completely changed how I look at arrays. Instead of using extra memory like HashSet, I learned how to store state inside the array itself. That’s a powerful mindset shift for interviews 🚀 ⚡ Interview Insight (High-Value Pattern): Whenever you see: Numbers in range [1, n] or [0, n] Need to find missing / duplicate elements Constraint of O(1) space 👉 Think Index as Hash Key This is a top-tier pattern asked in product-based companies. Consistency is the real key 🔑 #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Algorithms #Array #InterviewPrep #Optimization #Day8 ##MCA #lnct #100DaysOfCode #SoftwareEngineering #InPlaceAlgorithms #TechLearning #JavaDeveloper
To view or add a comment, sign in
-
-
Leetcode Practice - 15. 3Sum The problem is solved using JAVA. Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duplicate triplets. Example 1: Input: nums = [-1,0,1,2,-1,-4] Output: [[-1,-1,2],[-1,0,1]] Explanation: nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0. nums[1] + nums[2] + nums[4] = 0 + 1 + (-1) = 0. nums[0] + nums[3] + nums[4] = (-1) + 2 + (-1) = 0. The distinct triplets are [-1,0,1] and [-1,-1,2]. Notice that the order of the output and the order of the triplets does not matter. Example 2: Input: nums = [0,1,1] Output: [] Explanation: The only possible triplet does not sum up to 0. Example 3: Input: nums = [0,0,0] Output: [[0,0,0]] Explanation: The only possible triplet sums up to 0. Constraints: 3 <= nums.length <= 3000 -105 <= nums[i] <= 105 #LeetCode #Java #CodingPractice #ProblemSolving #DSA #Array #DeveloperJourney #TechLearning
To view or add a comment, sign in
-
-
Day 6 of Java with DSA Journey 🚀 📌 Topic: Max Consecutive Ones (LeetCode 485) 💭 Quote: "Progress is about maintaining momentum—just like a streak of consecutive ones." ✨ What I learned today: 🔹 State Tracking: Learned how to maintain a current streak vs a maximum streak — a key concept for sequence-based problems. 🔹 The Power of Resetting: Understanding when to reset the counter (on encountering 0) is crucial to solving streak problems correctly. 🔹 Simple Yet Powerful Logic: No complex data structures needed — just a clean linear scan with strong logic. 🔹 Performance: ✔️ Time Complexity: O(n) (Single pass) ✔️ Space Complexity: O(1) (Only variables used) 🧠 Problem Solved: ✔️ Max Consecutive Ones 💡 Key Insight: This problem is a foundation for the Sliding Window pattern. Instead of managing two pointers, we track a running window of 1s that resets when a 0 appears. ⚡ Interview Insight – Using Math.max(): Instead of writing: if (current > max) max = current; Using: max = Math.max(max, current); makes the code cleaner and more professional — a small detail that reflects strong coding practices. 📈 Growth Reflection: With each problem, I’m focusing on: 🔹 Explaining logic clearly and step-by-step (important for interviews) 🔹 Thinking in patterns (like Sliding Window & State Tracking) 🔹 Writing clean and optimized code like a software engineer Consistency is the real key 🔑 #DSA #LeetCode #Java #CodingJourney #SlidingWindow #ProblemSolving #Day6 #SoftwareEngineer #Algorithms #Array #MCA #lnct #100DaysOfCode #Algorithms #SoftwareEngineering #InPlaceAlgorithms #TechLearning #JavaDeveloper
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟯: 𝗣𝗶𝘃𝗼𝘁𝗶𝗻𝗴 𝘄𝗵𝗲𝗻 𝘁𝗵𝗲 𝘀𝗶𝗺𝗽𝗹𝗲 𝗮𝗽𝗽𝗿𝗼𝗮𝗰𝗵 𝗳𝗮𝗶𝗹𝘀. 🧠 The screenshot doesn’t show the struggle, It just shows the final Accepted code. ✅𝗙𝗼𝗿 𝗗𝗮𝘆 𝟯, I tackled this LeetCode problem: "𝟮𝟴𝟯𝟵. 𝗖𝗵𝗲𝗰𝗸 𝗶𝗳 𝗦𝘁𝗿𝗶𝗻𝗴𝘀 𝗖𝗮𝗻 𝗯𝗲 𝗠𝗮𝗱𝗲 𝗘𝗾𝘂𝗮𝗹 𝗪𝗶𝘁𝗵 𝗢𝗽𝗲𝗿𝗮𝘁𝗶𝗼𝗻𝘀 𝗜." My goal was simple: just get that Java solution 𝗔𝗰𝗰𝗲𝗽𝘁𝗲𝗱. 𝗧𝗵𝗲 𝗙𝗶𝗿𝘀𝘁 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: I initially started with a classic iterative method, trying to loop through and swap indices to check equality. But I kept hitting unexpected logic errors that were overcomplicating a simple problem. I realized the "obvious" way wasn't the "correct" way. 𝗧𝗵𝗲 𝗣𝗶𝘃𝗼𝘁: Instead of getting stuck on the iteration, I looked at the core constraint. The operation only allows swaps between characters exactly 2 indices apart (e.g., indices 0 and 2, 1 and 3). 𝗧𝗵𝗲 𝗕𝗿𝗲𝗮𝗸𝘁𝗵𝗿𝗼𝘂𝗴𝗵: I realized that if strings are length 4, characters at even indices (0, 2) can only ever interact with each other. The same applies to odd indices (1, 3). So, instead of looping, I just needed to compare those two specific pairs directly. ✅𝗧𝗵𝗲 𝗿𝗲𝘀𝘂𝗹𝘁: I simplified the code into two simple comparison blocks and hit Submit. That final 𝟭𝗺𝘀 𝗥𝘂𝗻𝘁𝗶𝗺𝗲 (𝗕𝗲𝗮𝘁𝗶𝗻𝗴 𝟵𝟵.𝟲𝟲%) was the perfect confirmation that the pivot was the right choice. Sometimes the best engineering decision is to tear down what isn't working and start with a cleaner logic. #Java #JavaDeveloper #DSA #Strings #BuildInPublic #EngineeringStudent #DAY3
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