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
Symmetric Tree Problem in DSA Journey
More Relevant Posts
-
Day 61/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Median of Two Sorted Arrays A classic hard problem with a clever binary search approach. Problem idea: Find the median of two sorted arrays without fully merging them. Key idea: Use binary search on the smaller array to partition both arrays. Why? • We want left half and right half to be balanced • All elements in left ≤ all elements in right How it works: • Pick a cut in array1 • Derive cut in array2 • Check partition validity using boundary elements If valid → we found the median If not → adjust the partition Time Complexity: O(log(min(m, n))) Space Complexity: O(1) Big takeaway: Binary search isn’t just for searching — it can be used to optimize partitions and positions. This one really builds intuition. 🔥 Day 61 done. #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearch #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
🚀 Day 44/60 – DSA Challenge Today’s problem was about finding the minimum element in a rotated sorted array using Binary Search 🔍 🔍 Problem Solved: Given a sorted array that has been rotated, find the minimum element efficiently. 🧠 Approach I Used: Instead of scanning the array linearly, I used Binary Search: Compare the middle element with the last element If the middle is greater → minimum lies on the right side Otherwise → minimum lies on the left side Keep shrinking the search space until the answer is found ⚡ Key Insight: The comparison with the last element helps determine which part of the array is sorted and where the minimum lies. 📈 Complexity: Time: O(log n) Space: O(1) 🎯 What I Learned: Binary Search can be adapted to solve rotated array problems Understanding array structure is more important than memorizing logic Edge cases and boundary handling are crucial for correctness Improving step by step, one problem at a time 🔥 #Day44 #DSAChallenge #BinarySearch #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
📘 DSA Journey — Day 27 Today’s focus: Binary Search on modified arrays. Problem solved: • Search in Rotated Sorted Array (LeetCode 33) Concepts used: • Binary Search • Identifying sorted halves • Conditional search space reduction Key takeaway: This problem extends binary search to a rotated sorted array, where the array is not fully sorted but divided into two sorted parts. At each step, we: • Find the mid element • Check which half (left or right) is sorted • Decide whether the target lies in the sorted half • Eliminate the other half This allows us to still achieve O(log n) time complexity. Continuing to strengthen fundamentals and problem-solving consistency. #DSA #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
Day 59/75 — Merge Sorted Array Today’s problem was about merging two sorted arrays into one sorted array in-place. Approach: • Start from the end to avoid overwriting elements • Use three pointers: i (nums1), j (nums2), k (merged position) • Place the larger element at the end and move backwards Key logic: while (i >= 0 && j >= 0) { if (nums1[i] > nums2[j]) { nums1[k--] = nums1[i--]; } else { nums1[k--] = nums2[j--]; } } while (j >= 0) { nums1[k--] = nums2[j--]; } Time Complexity: O(m + n) Space Complexity: O(1) A simple yet important problem that reinforces two-pointer technique. 59/75 🚀 #Day59 #DSA #TwoPointers #Arrays #Java #Algorithms #LeetCode
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 8/30 — DSA Challenge 🚀 Problem: Search a 2D Matrix II Topic: Matrix + Binary Search Pattern Difficulty: Medium Approach: Started from top-right corner of the matrix If current element == target → return true If current element < target → move down If current element > target → move left Mistake / Challenge: Initially tried applying binary search like previous problem (LeetCode 74) Realized matrix is not globally sorted, so that approach fails Fix: Used optimal “staircase search” approach Reduced time complexity efficiently Key Learning: Not all sorted matrices can be treated as 1D arrays Recognize pattern: row-wise + column-wise sorted → use pointer approach Time Taken: 45 minutes Consistency check ✅ See you on Day 9. GitHub Repo: https://lnkd.in/gHW9vKUf #DSA #LeetCode #Java #Matrix #BinarySearch #LearningInPublic
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
-
-
📘 DSA Journey — Day 28 Today’s focus: Binary Search for minimum in rotated arrays. Problem solved: • Find Minimum in Rotated Sorted Array (LeetCode 153) Concepts used: • Binary Search • Identifying unsorted half • Search space reduction Key takeaway: The goal is to find the minimum element in a rotated sorted array. Using binary search, we compare the mid element with the rightmost element: • If nums[mid] > nums[right] → minimum lies in the right half • Else → minimum lies in the left half (including mid) This works because the rotation creates one unsorted region, and the minimum always lies in that region. By narrowing the search space each time, we achieve O(log n) time complexity. This problem highlights how slight modifications in array structure still allow binary search to work efficiently with the right observations. Continuing to strengthen binary search patterns and consistency in problem solving. #DSA #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 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
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
-
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