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
Mastering Java DSA with Recursion
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) 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
To view or add a comment, sign in
-
-
DSA journey 🚀 📌 LeetCode #1 – Two Sum 💻 Language: Java 🔹 Approach: Use two nested loops to check all possible pairs Compare the sum of each pair with the target Return indices once the matching pair is found ⏱ Time Complexity: O(n²) 🧩 Space Complexity: O(1) Consistency over perfection 💯 #DSA #Java #LeetCode #ProblemSolving #LearningInPublic #DSAWithedSlash
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
-
-
🚀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
-
-
Java really said “not so fast” today 😵💫☕ I wrote two innocent lines — String str = "127"; Integer a = 127; — and assumed life was simple 🤷♂️. Turns out, the JVM had a whole strategy running behind the scenes 🤯🧠. String Pool here, Integer Cache there, object reuse everywhere — and suddenly == started acting suspicious 😄⚙️. Big reminder: Java isn’t just syntax, it’s a lesson in memory, performance, and intent 🚀. If this stuff ever confuses you, congrats — you’re not stuck, you’re leveling up 💪 #Java #JVM #Coding #Programming
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
-
-
🚀Day 6 of #120DaysOfCode 📌 Problem: Third Maximum number(414) 📌 Language: Java 🔍Approach . Duplicates must be ignored . Sorting is easy but not optimal . We only need top 3 distinct values 🔥 Approaches Maintain three variable . max1 --> largest . max2 --> second largest . max3 --> third largest ⏱️ Time and Space Complexity Time Complexity: O(n) Space complexity: O(1) 🔥One problem closer to mastery #120DaysOfCode #Day6 #Java #Array #Leetcode #ProblemSolving #Consistency #LearningEveryday #LearningPublic #DSA
To view or add a comment, sign in
-
-
DSA journey 🚀 📌 LeetCode #1137 – N-th Tribonacci Number 💻 Language: Java 🔹 Approach: Handle base cases (n == 0, n == 1, n == 2) Use an iterative approach instead of recursion Track the last three values to build the Tribonacci sequence ⏱ Time Complexity: O(n) 🧩 Space Complexity: O(1) Consistency over perfection 💯 #DSA #Java #LeetCode #ProblemSolving #LearningInPublic
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