Mastering DSA with Java — Recursion (Practice) Today’s practice problem was a mix of logic + recursion: 🔹 Convert a Number to Words using Recursion Instead of processing digits left-to-right directly, recursion flips the thinking: Break the number using % 10 Go deeper with n / 10 Print digits while returning from the recursive calls 💡 What this problem teaches: How recursion naturally handles reverse order The importance of base cases (n == 0) Using recursion to process digits without extra data structures Understanding how work happens after the recursive call #DSA #Java #Recursion #CodingPractice #ProblemSolving #LearnInPublic #JavaDeveloper #DataStructures
Mastering DSA with Java: Recursive Number to Words Conversion
More Relevant Posts
-
Mastering DSA with Java — Recursion (Advanced Practice) Today’s recursion practice pushed things to the next level 📌 Problem: Count all contiguous substrings that start and end with the same character. This wasn’t about brute force — it was about thinking recursively. 🔹 Broke the string into smaller subproblems 🔹 Used the inclusion–exclusion idea to avoid double counting 🔹 Handled multiple base cases (n == 1, n <= 0) 🔹 Added the final condition only when characters at both ends match 💡 Key takeaways from this problem: Recursion isn’t always linear — sometimes it branches Overlapping subproblems need careful handling A small formula can replace multiple loops Understanding the logic flow matters more than memorizing code Problems like this really teach you how recursion works under the hood, not just how to use it. #DSA #Java #Recursion #ProblemSolving #CodingJourney #LearnInPublic #DataStructures #JavaDeveloper
To view or add a comment, sign in
-
-
Mastering DSA with Java — Recursion (Practice) Practiced another recursion problem today: 🔹 Find Length of a String using Recursion Instead of using loops or built-in functions, the idea here is simple: Reduce the string one character at a time Let recursion handle the rest Count while returning back through the call stack 💡 What this problem reinforces: Strong base case thinking (length == 0) How recursive calls shrink the problem size Understanding work during return time (+1) Seeing recursion as a replacement for iteration #DSA #Java #Recursion #CodingPractice #ProblemSolving #LearnInPublic #JavaDeveloper #DataStructures
To view or add a comment, sign in
-
-
🚀Day 20 of #120DaysOfCode 📌 Problem: Reverse Integer(7) 📌 Language: Java Algorithm: 1. Initialize rev = 0 2. While x != 0 . Extract digit . Check overflow . Update rev 3. Return rev ⏱️ Time and Space Complexity Time Complexity: O(logn) Space complexity: O(1) 🔥One problem closer to mastery #120DaysOfCode #Day20 #Java #Array #Leetcode #ProblemSolving #Consistency #LearningEveryday #LearningPublic #DSA
To view or add a comment, sign in
-
-
📌 DSA Series — Day 2 : Problem 1 | Arrays Problem: Remove Duplicates from Sorted Array 🔹 Approach (Two-Pointer Technique): Maintain a pointer (firstPtr) that tracks the position of the last unique element. Traverse the array and overwrite duplicates by shifting only unique elements forward. Since the array is sorted, duplicates always appear consecutively. 🔹 Why this works: Sorted order guarantees that a change in value indicates a new unique element. This allows in-place modification without using extra memory. 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(1) 🔹 Java Implementation: class Solution { public int removeDuplicates(int[] nums) { if (nums.length == 0) return 0; int firstPtr = 0; for (int item : nums) { if (nums[firstPtr] != item) { nums[++firstPtr] = item; } } // +1 converts index to count of unique elements return firstPtr + 1; } } 🔹 Key Insight: The trick is realizing that the problem cares about the count of unique elements, not the remaining values beyond that count. 📈 Continuing my daily DSA problem-solving series. #DSA #Arrays #Java #TwoPointers #ProblemSolving #StriversA2Z #CodingJourney
To view or add a comment, sign in
-
-
day 95/100 #leetcodegrinding I solved the “Capacity To Ship Packages Within D Days” problem — a classic example of Binary Search on the Answer. 💡 Key idea: The total number of days decreases as the ship capacity increases, making it a monotonic relationship. Binary search lets us efficiently find the minimum capacity needed to ship all packages on time. 🧠 What I practiced: Binary search over a solution space, not indices Calculating days needed using ceiling division Handling large arrays efficiently Writing clean and optimized Java code Problems like these strengthen intuition for optimizing under constraints 📦🚀 #DSA #ProblemSolving #Java #BinarySearch #LeetCode #Algorithms #DailyCoding #Consistency
To view or add a comment, sign in
-
-
🚀 Problem-Solving Win | Java DSA Solved “Missing Number in Array” on GeeksforGeeks and handled a tricky edge case involving integer overflow. ✔Instead of changing the logic, I focused on correct data type handling: ✔Used long for large arithmetic operations ✔Ensured operands were evaluated as long ✔Safely type-cast the final result back to int, as required ✅ Final approach: int missingNum(int arr[]) { // code here long len = arr.length; long sum = ((len+1)*(len+2))/2; for(int i=0; i<len;i++){ sum-=arr[i] ; } int ans = (int)sum; return ans; } 💡 Key takeaways: • Operand data types matter as much as result type • Use long for large arithmetic operations • Type-cast back carefully when the return type is int • Small debugging moments like these strengthen core Java and DSA fundamentals 💻📈 #GeeksforGeeks #Java #DSA #ProblemSolving #Debugging #CodingJourney #Learning
To view or add a comment, sign in
-
-
🚀 Strengthening DSA Fundamentals – Merge Sort (Java) Today, I worked on implementing Merge Sort in Java, focusing on identifying and fixing common pitfalls such as: Proper creation of temporary arrays Correctly copying data before merging Handling index boundaries during recursion Writing clean and readable merge logic This exercise helped me reinforce: ✅ Divide & Conquer strategy ✅ Recursive thinking ✅ Time & space complexity analysis (O(n log n) time, O(n) space) Debugging algorithms like Merge Sort has significantly improved my problem-solving approach and attention to edge cases. 📌 Learning DSA is not just about writing code — it’s about understanding why it works. #DSA #Java #MergeSort #Recursion #ProblemSolving #LearningJourney #CodingPractice
To view or add a comment, sign in
-
-
Important Methods of Arrays Class in Java The Arrays class in Java provides powerful sort() methods to make array handling simple and efficient 🚀 🔹 Sort primitive arrays like int, long, short 🔹 Sort complete arrays or specific ranges 🔹 Sort object arrays using Comparator for custom ordering 💡 Why use Arrays.sort()? ✔ Optimized and faster than manual sorting ✔ Easy to use and readable code ✔ Supports both primitive and object data types #Java #JavaProgramming #Arrays #DSA #Coding #LearningJava #StudentDeveloper #ProgrammingBasics
To view or add a comment, sign in
-
-
🧠 DSA Wednesday | LeetCode – 4Sum (Java) Solved 4Sum using sorting + two pointers 💡 🔍 Problem: Given an array, find all unique quadruplets whose sum equals the target. ✨ Key ideas that make this work: • Sorting the array → enables two-pointer approach • Skipping duplicates → avoids repeated answers • Using long sum → prevents integer overflow (🔥 important line!) 📌 Why this approach matters: Brute force is slow ❌ Optimized logic = clean, efficient, and interview-ready ✅ DSA is not about writing long code — it’s about thinking smart and handling edge cases. 👉 Would you like a breakdown of the duplicate-skipping logic next? #DSA #LeetCode #Java #ProblemSolving #WednesdayWisdom #CodingJourney #TwoPointers #InterviewPrep
To view or add a comment, sign in
-
-
Day 40 of Java DSA ✅ | Trie (Prefix Tree) Basics Covered! 🚀 Today I learned the fundamentals of Trie (Prefix Tree) — a powerful data structure used for fast string operations like prefix search, autocomplete, and dictionary implementations. 🔹 Key takeaways: Efficient insertion and search in O(L) time (L = length of word) Optimized for prefix-based queries Widely used in search engines, spell checkers & auto-suggestions Step by step, building strong foundations in DSA with Java. Consistency > Motivation. 💯 #DSA #Java #Trie #DataStructures #ProblemSolving #CodingJourney #LearningInPublic #BTech #DeveloperMindset #Consistency #Day40
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