🚀 Day 62 of #100DaysOfCode 🌱 Topic: Trees / Recursion ✅ Problem Solved: LeetCode 112 – Path Sum 🛠 Approach: Used DFS (recursion) to explore all root-to-leaf paths. Base Case: If node is null → return false If leaf node: Check if target == node.val → return result Otherwise: Reduce target → target - node.val Recurse on left and right subtree #100DaysOfCode #Day62 #DSA #Trees #Recursion #DFS #LeetCode #Java #BinaryTree #ProblemSolving #CodingJourney #Consistency
Day 62: LeetCode 112 Path Sum with DFS Recursion
More Relevant Posts
-
Day 41 of Daily DSA 🚀 Solved LeetCode 20: Valid Parentheses ✅ Problem: Given a string containing only (), {}, [], determine if the input string is valid. Rules: Open brackets must be closed by the same type Open brackets must be closed in the correct order Every closing bracket must have a matching opening bracket Approach: Used a Stack to track opening brackets and validate matching pairs. Steps: Traverse the string Push opening brackets onto the stack For closing brackets → check top of stack If it matches → pop Else → return false At the end, stack should be empty ⏱ Complexity: • Time: O(n) • Space: O(n) 📊 LeetCode Stats: • Runtime: 3 ms (Beats 87.41%) ⚡ • Memory: 43.37 MB A classic stack problem that builds strong fundamentals for expression parsing & validation. #DSA #LeetCode #Java #Stack #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Today I solved LeetCode 543 – Diameter of Binary Tree. 🧩 Problem Summary: Given the root of a binary tree, return the diameter of the tree. The diameter is defined as the length of the longest path between any two nodes in the tree. This path may or may not pass through the root. 💡 Key Concepts Used: Binary Trees Recursion Depth First Search (DFS) Height calculation 🧠 Approach: Use DFS to calculate the height of each subtree. For every node: Compute left subtree height Compute right subtree height The diameter at that node = left height + right height Keep track of the maximum diameter seen so far. Return the height of the current node: 1 + max(left height, right height) ⏱ Time Complexity: O(N) — Each node is visited once. 📚 What I Learned: How to compute multiple values (height + diameter) in one traversal. Understanding that diameter doesn’t always pass through root. Optimizing recursive tree problems. Strengthening DFS and recursion concepts. Tree problems are sharpening my problem-solving skills Consistency and daily practice make the difference #LeetCode #DSA #BinaryTree #DiameterOfBinaryTree #DFS #Recursion #Java #CodingJourney #ProblemSolving #100DaysOfCode #TechGrowth
To view or add a comment, sign in
-
-
🚀 Day 64 of #100DaysOfCode Solved 222. Count Complete Tree Nodes on LeetCode 🔗 🧠 Key Insight: In a complete binary tree, all levels are fully filled except possibly the last, and nodes are as left as possible. 👉 This property helps us optimize beyond simple traversal ⚙️ Approach (Simple DFS - Your Solution): 1️⃣ If root is null → return 0 2️⃣ Recursively count: 🔹 left = countNodes(root.left) 🔹 right = countNodes(root.right) 3️⃣ Total nodes: 👉 1 + left + right ⏱️ Time Complexity: Current → O(n) Optimized → O(log² n) 📦 Space Complexity: O(h) #100DaysOfCode #LeetCode #DSA #BinaryTree #Recursion #DivideAndConquer #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
Day 76 - Symmetric Tree Applied mirror comparison technique to validate symmetric binary trees. Approach: • Base cases for null nodes • Compare node values • Cross-check children recursively Time Complexity: O(n) Space Complexity: O(h) #Day76 #LeetCode #CodingJourney #DSA #Java #BinaryTree #LearningDaily
To view or add a comment, sign in
-
-
Day 74 - Univalued Binary Tree Checking whether all nodes in a binary tree share the same value using recursion. Approach: • Store root value • Traverse the tree recursively • Compare each node with root value • Return false if any mismatch is found Key Insight: Recursion simplifies tree traversal and validation Time Complexity: O(n) #Day74 #LeetCode #Java #CodingPractice #TechJourney #DSA #BinaryTree
To view or add a comment, sign in
-
-
Day 68 of My DSA Journey Today’s problem: Symmetric Tree 🌳 Problem Statement Given a binary tree, check whether it is a mirror of itself (symmetric around its center). Key Insight A tree is symmetric if: Left subtree is a mirror of the right subtree Compare nodes in a cross manner: Left → Left with Right → Right Left → Right with Right → Left 🧠 Approach Use recursion to compare two nodes at a time Base cases: If both nodes are null → symmetric If one is null → not symmetric Check: Values are equal Outer and inner pairs match ⚡ Complexity Time: O(n) Space: O(h) (recursion stack) ✨ What I Learned This problem improved my understanding of recursion and how to think in terms of mirror structures instead of normal traversal. Consistency is the key 🔑 — one problem at a time! #DSA #Java #BinaryTree #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 97/200 – LeetCode Challenge Solved “Largest Rectangle in Histogram” (Hard) today. This problem is a great example of how powerful the Monotonic Stack technique can be. Instead of brute force, we efficiently determine how far each bar can extend to compute the maximum rectangle area. Using a monotonic increasing stack to track indices. Identifying left and right boundaries for each bar. Every day is making data structures feel more intuitive! #Day96 #LeetCode #Java #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 63 — LeetCode Progress (Java) Problem: Crawler Log Folder Required: Given a list of folder operations, return the minimum number of operations needed to go back to the main folder. Idea: Track the current depth like a counter — move forward increases depth, move back decreases depth, and staying does nothing. Approach: Initialize a variable to track current depth. Traverse each log: "../" → move up (decrease depth, but not below 0) "./" → stay in the same folder "x/" → move into a subfolder (increase depth) Final depth represents the number of steps needed to return to the main folder. Time Complexity: O(n) Space Complexity: O(1) #LeetCode #DSA #Java #Simulation #Strings #Algorithms #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 20/100: The "Cheat Code" for String Rotations 🔄 I’m back on the grind! Today’s challenge was checking if one string is a rotation of another (e.g., "waterbottle" and "erbottlewat"). The Strategy: Instead of writing complex loops to shift characters, I used the Concatenation Trick: 1️⃣ Check if lengths are equal. 2️⃣ Create a new string by adding the first string to itself (s1 + s1). 3️⃣ Check if the second string exists inside that combined string. It’s a simple, elegant O(n) solution that shows how sometimes "working smarter" with data structures beats "working harder" with loops. 20% of the way there. Let's keep moving! 🚀 #100DaysOfCode #Java #DSA #Strings #ProblemSolving #Unit2 #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
🚀 LeetCode Challenge 14/50 💡 Approach: Sort + Two Pointers Brute force checks every triplet — that's O(n³)! Instead, I sorted the array first, then fixed one element and used Two Pointers to find the remaining pair in O(n). Result? O(n²) overall! 🔍 Key Insight: → Sort the array first to enable Two Pointer technique → Fix element at index i, use left & right pointers for the rest → sum < 0 → move left pointer right (need bigger value) → sum > 0 → move right pointer left (need smaller value) → sum = 0 → found a triplet! Skip duplicates carefully 📈 Complexity: ❌ Brute Force → O(n³) Time ✅ Sort + Two Pointer → O(n²) Time, O(1) Space The hardest part wasn't the logic — it was handling duplicates correctly. Details make the difference between a good solution and a great one! 🎯 #LeetCode #DSA #TwoPointers #Java #ADA #PBL2 #LeetCodeChallenge #Day14of50 #CodingJourney #ComputerEngineering #AlgorithmDesign #3Sum
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