Mastering Java & DSA Through LeetCode Day 34 Today I solved a Medium-level Tree problem that strengthened my understanding of Prefix Sum + DFS — a powerful pattern used in many interview questions. LeetCode Problem: 437. Path Sum III Problem Summary: Given a binary tree and a target sum, we need to find the number of paths where the sum of node values equals the target. The path must go downward (parent → child), but it doesn’t need to start from the root. Key Insight: Instead of checking all possible paths (which is inefficient), we use: Prefix Sum HashMap to store frequencies DFS traversal This helps reduce time complexity from O(n²) → O(n) ⚡ Approach: Maintain a running sum while traversing the tree Check if (currentSum - target) exists in the map Use backtracking to maintain correct state What I Learned: How prefix sum works in trees (not just arrays!) Optimizing brute-force solutions Importance of hashmap in reducing complexity Consistency Update: Day 34 of solving DSA problems daily 💪 Small steps every day = big results over time #LeetCode #Java #DSA #CodingJourney #100DaysOfCode #SoftwareEngineering #PlacementPreparation #CodingInterview
Mastering Java & DSA through LeetCode: Prefix Sum + DFS
More Relevant Posts
-
🚀 Day 37 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Two-Pointer Technique 🧩 Problem Solved: Squares of a Sorted Array Problem: Given a sorted array of integers (including negatives), return a new array of the squares of each number, also sorted in non-decreasing order. Approach: Used a two-pointer approach from both ends of the array. Compared squares of elements and filled the result array from the end to maintain sorted order efficiently. Key Learning: ✔️ Handling negative values in sorted arrays ✔️ Using two-pointer technique for optimal solutions ✔️ Avoiding extra sorting to achieve O(n) time complexity If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 60 of My Java DSA Journey Today I solved an important Binary Search Tree problem: 💡 Recover Binary Search Tree (RBST) 🧠 Approach: • Performed inorder traversal of BST • Identified violations where the inorder sequence is not sorted • Tracked misplaced nodes using three pointers: first (first violation) middle (adjacent swap case) last (non-adjacent swap case) • Swapped the incorrect node values to restore BST properties 🔍 Key Insight: Inorder traversal of a BST should always be sorted. If two nodes are swapped, we can detect them by finding “inversion points” in the inorder sequence and fix the tree without changing structure. ⚡ What I learned: • Strong understanding of BST inorder properties • How to detect structural violations in trees • Handling adjacent vs non-adjacent swapped nodes • Importance of pointer tracking in recursive traversal 🔥 Complexity: • Time: O(n) • Space: O(h) (recursion stack) 🎯 Takeaway: Tree problems are not just about traversal — they test your ability to observe patterns in structure and fix them with minimal changes. #Day60 #90DaysOfCoding #DSA #BST #Java #ProblemSolving #BinaryTree
To view or add a comment, sign in
-
-
🚀 I thought I knew Java Arrays… until I actually revised them properly. Most beginners memorize syntax like: int[] arr = new int[5]; But interviews don’t test syntax. They test understanding. Here’s what actually matters: • Why array index starts from 0 • How memory is allocated internally • Why arrays are fixed size • Why O(1) access time makes arrays powerful • When to use Array vs ArrayList If your array basics are weak, Data Structures will feel difficult. Today I revised: ✔ Declaration & Initialization ✔ 2D and Jagged Arrays ✔ Traversal methods ✔ Arrays utility methods Strong fundamentals > Fancy topics. Are your array basics really strong? #Java #DSA #Programming #JavaDeveloper #CodingJourney
To view or add a comment, sign in
-
-
📅 Day 10 – Strings in Java 📚 Topic: String Manipulation (Hashing) Today I solved the problem of checking whether two strings are anagrams using an efficient frequency-count approach. This helped me understand how hashing can be used to compare character distributions instead of sorting. ✔ Key Learnings: • Applied hashing using a frequency array • Improved understanding of character frequency comparison • Learned how to optimize from sorting (O(n log n)) to linear time (O(n)) Building problem-solving skills step by step and focusing on writing efficient code 🚀 #DSA #Strings #Java #ProblemSolving #LearningJourney
To view or add a comment, sign in
-
-
🚀 Day 36 / 180 – DSA with Java 🚀 📘 Topic Covered: Binary Search (Peak Finding) 🧩 Problem Solved: Find Peak Element Problem: Given an array, find a peak element (an element greater than its neighbors) and return its index. Approach: Used Binary Search by comparing the middle element with its neighbors. Based on the increasing or decreasing slope, moved towards the side where a peak must exist, reducing the search space efficiently. Key Learning: ✔️ Applying binary search on unsorted arrays using patterns ✔️ Understanding how slope direction guides decisions ✔️ Solving peak problems in O(log n) time If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #BinarySearch #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 51 – Mastering LinkedList in Java Today I explored one of the most important data structures in Java Collections – LinkedList. 🔍 Key Learnings: ✔ Understood how LinkedList works internally using Doubly Linked List (nodes) ✔ Learned the difference between ArrayList vs LinkedList (dynamic vs node-based storage) ✔ Explored constructors and how to copy data using Collection constructor ✔ Deep dive into Polymorphism & Loose Coupling in real-time usage 💡 Accessing Elements Techniques: 🔹 For Loop (get(index)) 🔹 Enhanced For Loop (for-each) 🔹 Iterator (forward traversal) 🔹 ListIterator (forward + backward traversal) ⚡ Realization: Understanding how data is accessed and traversed is just as important as storing it. Concepts like Iterator vs ListIterator are very crucial for interviews. 📈 Step by step, building strong foundations in Core Java & Collections Framework #Java #LinkedList #CollectionsFramework #CoreJava #Programming #LearningJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Solved LeetCode 17 – Letter Combinations of a Phone Number using backtracking in Java. Approach: Mapped each digit (2–9) to its corresponding characters using a simple array for O(1) access. Then used backtracking to build combinations digit by digit. For every digit: Pick each possible character Append → explore next digit → backtrack Key idea: Treat it like a tree of choices, where each level represents a digit and branches represent possible letters. Key learnings: Backtracking = build → explore → undo StringBuilder helps avoid unnecessary string creation Problems like this are about systematic exploration of choices Time Complexity: O(4^n * n) Space Complexity: O(n) recursion stack + output Consistent DSA practice is strengthening pattern recognition day by day. #Java #DSA #Backtracking #LeetCode #CodingInterview #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 66 of #100DaysOfLeetCode 💻✅ Solved #3427. Sum of Variable Length Subarrays problem in Java. Approach: • Iterated through each index of the array • Determined the starting index using i - nums[i] • Ensured the start index does not go below 0 • Calculated sum of elements from start to current index i • Added each subarray sum to the total Performance: ✓ Runtime: 1 ms (Beats 99.90% submissions) ✓ Memory: 45.22 MB (Beats 56.30% submissions) Key Learning: ✓ Practiced handling variable-length subarrays ✓ Improved understanding of index-based range calculations ✓ Strengthened nested loop logic for array problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #PrefixSum #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Today I worked on a problem that involved finding the maximum count of positive and negative numbers in a sorted array. Key idea: Used Binary Search to efficiently find: The first positive number The first non-negative number From this, we can calculate: Count of positive numbers Count of negative numbers Why Binary Search? Because the array is sorted, it helps reduce time complexity to O(log n) instead of scanning the entire array. What I learned: How to apply binary search beyond just finding elements How to think in terms of boundaries (first occurrence logic) Writing clean and optimized Java code 📌 Problem-solving is not just about coding, it's about thinking efficiently. Looking forward to learning more and improving every day! #Java #DSA #BinarySearch #CodingJourney #ProblemSolving #LearningEveryday
To view or add a comment, sign in
-
-
Day 89 of #100DaysOfLeetCode 💻✅ Solved #15. 3Sum problem in Java. Approach: • Sorted the array first • Fixed one element and used Two Pointers for the rest • Skipped duplicates to avoid repeated triplets • Adjusted pointers based on sum comparison Performance: ✓ Runtime: 30 ms (Beats 87.77% submissions) ✓ Memory: 59.02 MB (Beats 77.30% submissions) Key Learning: ✓ Mastered Two Pointer technique with sorting ✓ Learned handling duplicates efficiently ✓ Improved problem-solving for combination-based problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #TwoPointers #Arrays #Sorting #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
Explore related topics
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