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
Mastering DSA with Java Recursion Techniques
More Relevant Posts
-
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
-
-
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
-
-
🚀 Day 14 – Array vs ArrayList in Java (Key Differences & Why Arrays Still Matter) Why learn Array when we already have ArrayList? 🤔 At first I thought: “Why bother learning arrays when ArrayList exists?” But the truth is… 👉 You can’t master ArrayList without mastering Array first. Understanding data structures is a must for writing efficient Java programs. Today I compared Array and ArrayList and learned why arrays are still very important. 🧠 Why Array is Important? ✅ Foundation of all data structures ✅ Used internally by ArrayList, HashMap, etc. ✅ Faster access (O(1)) ✅ Less memory usage ✅ Works with primitive types (int, double, etc.) ✅ Best choice for performance-critical code 💡 When to use what? ✔ Use Array → When size is fixed & performance matters ✔ Use ArrayList → When size changes frequently & flexibility is needed 🔥 Final Thought Master arrays first. Advanced collections become easy automatically. #Day14 #Java #Array #ArrayList #DSA #JavaDeveloper #LearningJourney #ProgrammingBasics #Consistency
To view or add a comment, sign in
-
🚀 100 Days of DSA with Java | Day 5 Q7 🚀 📌 Problem of the Day: Equilibrium Index in an Array You are given an array Arr of N integers. Your task is to find the equilibrium index. 🔹 An index is called an equilibrium index if: 👉 Sum of elements on the left side = Sum of elements on the right side 👉 The element at the index itself is not included in either sum 📝 Important Rules: Array follows 0-based indexing If multiple equilibrium indices exist, return the left-most one If no equilibrium index is found, return -1 📊 Example: Arr = [1, 7, 3, 6, 5, 6] ✅ Output: 3 (Left sum = 1 + 7 + 3 = 11, Right sum = 5 + 6 = 11) 🎯 What I practiced today: Prefix sum optimization Reducing time complexity from O(N²) to O(N) Stronger understanding of array traversal logic 💡 Problems like this build a solid foundation for advanced DSA topics. 📅 Onward to the next challenge tomorrow! #100DaysOfDSA #DSAWithJava #ArrayProblems #ProblemSolving #CodingJourney #LearningInPublic #Consistency #JavaProgramming
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
-
-
🚀 Week 2 of Java DSA – Arrays Deep Dive This week, I went deeper into Arrays using Java and focused on improving problem-solving skills through medium-level DSA problems. 🔹 What I worked on: • Arrays in depth (indexing, patterns, edge cases) • Optimizing solutions using better logic • Solving medium-level array problems • Improving time complexity awareness while coding 🔹 Key learnings: • Small optimizations can make a big difference • Handling edge cases is as important as core logic • Writing efficient array-based solutions requires clarity, not speed Continuing the journey with more challenging problems ahead 🚀 #Java #DSA #Arrays #ProblemSolving #LearningInPublic #Consistency #LeetCode
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
-
-
📌 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
-
-
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
-
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