Day 82/150 🚀 LeetCode 112: Path Sum 🧠 Problem Given a binary tree and a targetSum, return true if there exists a root-to-leaf path where the sum of node values equals targetSum. 💡 Approach • Use DFS (Recursion) • Keep adding node values while traversing • Check at leaf node if sum equals target • Return true if any path matches ⏱ Time Complexity O(n) 📦 Space Complexity O(h) (recursion stack) ✅ Result: Accepted ⚡ Runtime: 3 ms 💾 Memory Beats: 94.93% #Day82 #LeetCode #BinaryTree #DFS #Recursion #DSA #CodingJourney #ProblemSolving
LeetCode 112: Path Sum in Binary Tree
More Relevant Posts
-
Day 87/150 🚀 LeetCode 199: Binary Tree Right Side View 🧠 Problem Return the values of nodes visible from the right side of a binary tree. 💡 Approach • Use DFS traversal • Traverse right subtree first, then left • If current level equals ans size → push node value • This ensures first node seen at each level is from right side ⏱ Time Complexity O(n) 📦 Space Complexity O(h) (recursion stack) ✅ Result: Accepted ⚡ Runtime: 2 ms #Day87 #LeetCode #BinaryTree #DFS #TreeTraversal #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 72/150 🚀 LeetCode 104: Maximum Depth of Binary Tree 🧠 Problem Given the root of a binary tree, return its maximum depth. 📌 Example Input → root = [3,9,20,null,null,15,7] Output → 3 💡 Approach • Use recursion (DFS) • Calculate left subtree depth • Calculate right subtree depth • Return max(left, right) + 1 ⏱ Time Complexity O(n) 📦 Space Complexity O(h) ✅ Result: Accepted ⚡ Runtime: 0 ms (Beats 100%) #Day72 #LeetCode #DSA #BinaryTree #Recursion #CodingJourney #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 86/150 🚀 LeetCode 222: Count Complete Tree Nodes 🧠 Problem Given the root of a complete binary tree, return the total number of nodes. 💡 Approach • Compute left height and right height • If equal → tree is perfect → nodes = (2^h - 1) • Else recursively count left + right subtree • Use properties of complete binary tree ⏱ Time Complexity O(log² n) 📦 Space Complexity O(log n) (recursion stack) ✅ Result: Accepted ⚡ Runtime: 0 ms (Beats 100%) #Day86 #LeetCode #BinaryTree #Recursion #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
𝐍𝐞𝐰 𝐏𝐲𝐇𝐆𝐅 𝐫𝐞𝐥𝐞𝐚𝐬𝐞 (𝐯0.2.10), featuring an early draft of local-only deep predictive coding networks. Get prospective configuration-like behaviours for a fraction of the compute cost. Three backends: - JAX vectorised (layer-wise matrix ops) - JAX nodalised (per-node updates) - Rust nodalised (per-node updates) Work in progress... 📦Code: https://lnkd.in/eZcDYz2c 📓Tutorial: https://lnkd.in/exfS3b5a
To view or add a comment, sign in
-
-
Day 84/150 🚀 LeetCode 124: Binary Tree Maximum Path Sum 🧠 Problem Find the maximum path sum in a binary tree. A path can start and end at any node. 💡 Approach • Use DFS (post-order traversal) • Ignore negative paths → max(0, left/right) • Update global max using left + right + root • Return max single path for recursion ⏱ Time Complexity O(n) 📦 Space Complexity O(h) (recursion stack) ✅ Result: Accepted ⚡ Runtime: 0 ms (Beats 100%) Hard problems getting comfortable 🌳 #Day84 #LeetCode #BinaryTree #DFS #Recursion #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 74/150 🚀 LeetCode 226: Invert Binary Tree 🧠 Problem Given the root of a binary tree, invert the tree and return its root. 📌 Example Input → root = [4,2,7,1,3,6,9] Output → [4,7,2,9,6,3,1] 💡 Approach • Use recursion • Swap left and right child • Recursively invert left subtree • Recursively invert right subtree ⏱ Time Complexity O(n) 📦 Space Complexity O(h) ✅ Result: Accepted ⚡ Runtime: 0 ms (Beats 100%) #Day74 #LeetCode #DSA #BinaryTree #Recursion #CodingJourney #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 245 of #500DaysOfCode Solved LeetCode 1559 – Detect Cycles in 2D Grid 🔄 💡 Approach: Traverse the grid using DFS Maintain a visited matrix While exploring neighbors: Move only in 4 directions (up, down, left, right) Only continue if the character matches Track parent cell (px, py) to avoid false cycle detection If we reach a visited cell that is not the parent → cycle found ✅ ⚡ Key Insight: Classic cycle detection in an undirected graph Parent tracking is crucial to avoid revisiting immediate previous node ⏱️ Complexity: Time: O(m × n) Space: O(m × n) (visited + recursion stack) ✨ Takeaway: Grid problems often map to graph traversal → think DFS/BFS + cycle detection patterns. Day 245 ✅ Still consistent 💪🔥 #LeetCode #DSA #DFS #Graphs #GridProblems #Consistency
To view or add a comment, sign in
-
-
Day 88/150 🚀 LeetCode 637: Average of Levels in Binary Tree 🧠 Problem Return the average value of nodes at each level of a binary tree. 💡 Approach • Use level order traversal (BFS) • For each level, calculate sum of nodes • Divide sum by number of nodes in that level • Store result in answer array ⏱ Time Complexity O(n) 📦 Space Complexity O(n) (queue for BFS) ✅ Result: Accepted ⚡ Runtime: 0 ms (Beats 100%) #Day88 #LeetCode #BinaryTree #BFS #LevelOrder #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 79/150 🚀 LeetCode 114: Flatten Binary Tree to Linked List 🧠 Problem Given the root of a binary tree, flatten it into a linked list in-place following preorder traversal. 📌 Example Input → root = [1,2,5,3,4,null,6] Output → [1,null,2,null,3,null,4,null,5,null,6] 💡 Approach • Use reverse preorder traversal • Flatten right subtree • Flatten left subtree • Connect nodes using previous pointer ⏱ Time Complexity O(n) 📦 Space Complexity O(h) ✅ Result: Accepted ⚡ Runtime: 0 ms (Beats 100%) #Day79 #LeetCode #DSA #BinaryTree #Recursion #CodingJourney #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 32 – LeetCode 1559: Detect Cycles in 2D Grid (Medium) Solved a grid + DFS cycle detection problem today 🧠 We treat the grid as a graph and use DFS to check if there’s a cycle of same characters (length ≥ 4), making sure we don’t count immediate backtracking as a cycle. 🔑 Key idea: Grid = implicit graph 🔍 Technique: DFS + visited + parent tracking 💡 Lesson: Most grid problems are just graph problems in disguise. #LeetCode #DSA #DFS #Graphs #100DaysOfCode
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