Two Trees, One Truth: Cracking Recursive Thinking 🌳 Solved LeetCode - 100. Same Tree today using recursion. The goal was simple: check whether two binary trees are structurally identical and have the same values. The solution clicked once I focused on the recursive base cases: -Both nodes are null → same -One is null → not same -Values differ → not same -Then recursively compare left and right subtrees. Key takeaway: Tree recursion becomes intuitive when you trust the base cases and let recursion handle the rest. Strengthening DSA fundamentals, one problem at a time. #LeetCode #DSA #BinaryTree #Recursion #JavaScript #ProblemSolving #LearnInPublic
Checking Binary Tree Equality with Recursion
More Relevant Posts
-
Two Ways to Reach the Same Sum 🌳 Solved LeetCode 112 - Path Sum using two recursive approaches. First approach: Accumulator pattern → Keep passing the running sum down the tree. Second approach: Reducing pattern → Subtract the current node value from the target and pass the reduced value forward. Both work, but they shape your thinking differently. Key takeaway: -Tree recursion isn’t just about correctness, it’s about choosing the right mental model. -Accumulate forward or reduce the goal backward. -Understanding both strengthens recursive intuition. #LeetCode #DSA #BinaryTree #Recursion #JavaScript #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
When Trees Meet Two Pointers: A Clean Twist on Two Sum 🌳 Solved LeetCode - Two Sum IV (Input is a BST) today. The approach clicked once I combined two ideas: Inorder traversal to leverage the BST’s sorted order Two-pointer technique to efficiently search for the target sum By converting the tree into a sorted sequence, the problem reduces to a classic two-sum pattern. Key takeaway: Many tree problems become simpler when you translate them into array patterns, the trick is knowing when it’s safe to do so. Building stronger cross-pattern intuition in DSA. #LeetCode #DSA #BinarySearchTree #TwoPointers #TreeTraversal #JavaScript #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
When One Path Isn’t Enough: Tracking All Valid Paths 🌳 Solved LeetCode 113 - Path Sum II today. Unlike Path Sum I, this version requires returning all root-to-leaf paths that match the target sum. The key shift: -Use recursion to explore paths -Maintain a current path array -Apply backtracking (push before recursion, pop after) Key takeaway: Whenever a problem asks for all combinations or all paths, think backtracking + state cleanup. This one strengthened my understanding of recursion with state management. #LeetCode #DSA #BinaryTree #Backtracking #Recursion #JavaScript #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
Seeing Trees Level by Level: Thinking in Breadth 🌳 Solved LeetCode 102 - Binary Tree Level Order Traversal today. Instead of going deep first, this problem flips the mindset to breadth-first traversal, processing nodes level by level using a queue. Each iteration captures all nodes at the current depth before moving deeper. Key takeaway: Tree problems aren’t only about DFS. When the question asks for levels, layers, or distance, BFS is the natural fit. This helped strengthen my intuition on choosing the right traversal based on the problem’s demand. #LeetCode #DSA #BinaryTree #BFS #TreeTraversal #JavaScript #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
I built a small tool called MultiJSON to simplify working with JSON. https://www.multijson.com 🙌 It helps you format, validate, and manage multiple JSON files in one place, and makes sharing clean JSON easy. The tool is fully client-side, so your data never leaves the browser. Built it to scratch a personal itch — sharing in case it helps others too. #JSON #WebDevelopment #SoftwareEngineering #DeveloperTools #PrivacyFirst #Coding #DataScience #JavaScript #WebDev
To view or add a comment, sign in
-
Fixing an Unbalanced Tree the Systematic Way 🌳 Solved LeetCode 1382 - Balance a Binary Search Tree today. The approach was clean and systematic: -Use inorder traversal to extract nodes in sorted order -Pick the middle element as the root -Recursively build left and right subtrees This guarantees a height-balanced BST without complex rotations. Key takeaway: Sometimes the best way to fix a structure is to rebuild it with the right invariants, not patch it incrementally. This problem nicely connected traversal, sorting, and divide-and-conquer thinking. #LeetCode #DSA #BinarySearchTree #TreeTraversal #DivideAndConquer #JavaScript #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
🚀 Day 4 of #LeetCodeDaily Problem: Remove Duplicates from Sorted Array (Easy) Remove duplicates in-place so each element appears only once and return the count of unique elements. 🔍 My Approach: Since the array is already sorted, duplicates are adjacent Used two pointers to overwrite duplicates while preserving order ⏱ Time: O(n) | 📦 Space: O(1) 💡 Learning: When input is sorted, many problems simplify into pointer-based solutions. #ProblemSolving #LeetCode #JavaScript #GeeksForGeeks #DSA #TwoPointers #30DaysDSAChallenge #LearningInPublic #InterviewPrep
To view or add a comment, sign in
-
-
Minimizing Maximum Pair Sum in Arrays 👉 Day 75 / Day 93 👈 23🔥 The idea: Sort the array Pair smallest with largest, second smallest with second largest, and so on Track the maximum sum among all pairs Example: nums = [3, 5, 2, 3] Sorted: [2, 3, 3, 5] Pairs: (2, 5) = 7, (3, 3) = 6 Maximum pair sum = 7 👉 This is the minimized maximum pair sum. #Coding #Algorithms #DataStructures #JavaScript #TypeScript #CleanCode #ProblemSolving #LeetCode #InterviewPrep
To view or add a comment, sign in
-
-
LeetCode 347: Top K Frequent Elements ✅ This one tested more than syntax — it tested patience. At first, broke the problem apart, and brought out every weapon I had: 1. HashMap for frequency counting 2. Array transformation for sorting 3. Clean extraction of the top-K results The key idea: Count frequency of each element using a map Convert the map into an array Sort by frequency in descending order Pick the top K elements ⏱ Time Complexity: O(n log n) — sorting the frequency array 🧠 Space Complexity: O(n) — storing frequencies and intermediate arrays 🧠 This problem reinforced something important for me: Feeling stuck doesn’t mean you’re failing — it means you’re learning. #LeetCode #DSA #JavaScript #ProblemSolving #Consistency #NeverGiveUp #LearnInPublic
To view or add a comment, sign in
-
-
Day 51/100 – Consistency > Motivation Today I explored JavaScript Math Methods and how to convert numbers into integers using different approaches. Here’s what I learned: Math.round(x) – Rounds to the nearest integer Math.ceil(x) – Rounds up to the nearest integer Math.floor(x) – Rounds down to the nearest integer Math.trunc(x) – Returns the integer part of a number It’s interesting how small built-in methods can make a big difference in handling real-world data and calculations. Halfway through this journey, one thing is clear: Consistency builds confidence. No matter how small the topic seems, every day adds up. #100DaysOfCode #Day51 #JavaScript #WebDevelopment #LearningInPublic #Consistency
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