Day 29/100 – LeetCode Challenge 🚀 Problem: Same Tree Approach: Used recursive traversal Compared corresponding nodes of both trees Checked: both nodes null → identical one null → not identical values mismatch → not identical recursively compared left and right subtrees Time Complexity: O(n) Space Complexity: O(h) Key takeaway: Many tree comparison problems reduce to simultaneous traversal of both trees. #LeetCode #100DaysOfCode #DSA #Java #BinaryTree #ProblemSolving
LeetCode Challenge: Same Tree Comparison
More Relevant Posts
-
𝗬𝗼𝘂 𝗵𝗮𝘃𝗲 𝗯𝗲𝗲𝗻 𝘂𝘀𝗶𝗻𝗴 𝗕𝗶𝗻𝗮𝗿𝘆 𝗦𝗲𝗮𝗿𝗰𝗵 𝘄𝗿𝗼𝗻𝗴. It is not just for sorted arrays. The real definition — "Eliminate HALF the search space with each decision." That one shift in thinking unlocks 20+ LeetCode problems. Swipe to see the template, live code, and 7 problems you can now solve with one pattern. 👇 Save this. 🔖 #DSA #BinarySearch #Java #LeetCode #CodingInterview #DebugWithPurpose
To view or add a comment, sign in
-
#day333 of #1001daysofcode problem statement (0257): Binary Tree Paths 💡 Approach: Used DFS recursion to explore all root-to-leaf paths in the binary tree. While traversing, I kept building the path string. When a leaf node is reached, the complete path is added to the result list. Example path format: 1->2->5 ⏱ Time Complexity: O(n) 🧠 Space Complexity: O(h) — recursion stack (h = height of the tree) Consistency in solving one problem every day 📈 #1001DaysOfCode #DSA #Java #LeetCode #ProblemSolving Shivam Mahajan #leetcode
To view or add a comment, sign in
-
-
#day332 of #1001daysofcode problem statement (0226): Invert Binary Tree The idea is to recursively swap the left and right child of every node in the tree. ⏱ Time Complexity: O(n) 🧠 Space Complexity: O(h) — recursion stack (h = height of tree) #1001DaysOfCode #DSA #Java #LeetCode #ProblemSolving Shivam Mahajan #leetcode
To view or add a comment, sign in
-
-
Day 36/100 – LeetCode Challenge 🚀 Problem: 3Sum Closest Approach: Sorted the array Fixed one element and applied the two-pointer technique Tracked the closest sum by comparing absolute differences Returned immediately if an exact match was found Time Complexity: O(n²) Space Complexity: O(1) Key takeaway: Many optimization problems are variations of classic patterns. Understanding 3Sum deeply makes solving 3Sum Closest straightforward. #LeetCode #100DaysOfCode #DSA #Java #TwoPointers #ProblemSolving #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 14 of #GeekStreak60 Today’s Problem: Find the Closest Pair from Two Sorted Arrays ✅ Solved using the Two Pointer approach since both arrays were sorted. Optimized from O(n × m) to O(n + m) by smart pointer movement. 📌 Key Takeaway: Whenever arrays are sorted, think Two Pointers first. @GeeksforGeeks @NPCI #GeekStreak60 #DSA #ProblemSolving #Java #CodingChallenge #NPCI
To view or add a comment, sign in
-
-
🚀 Day 14 of #GeekStreak60 Today’s Problem: Find the Closest Pair from Two Sorted Arrays ✅ Solved using the Two Pointer approach since both arrays were sorted. Optimized from O(n × m) to O(n + m) by smart pointer movement. 📌 Key Takeaway: Whenever arrays are sorted, think Two Pointers first. @GeeksforGeeks @NPCI #GeekStreak60 #DSA #ProblemSolving #Java #CodingChallenge #NPCI
To view or add a comment, sign in
-
-
🚀 Day 24 of #100DaysOfCode Solved 167. Two Sum II – Input Array Is Sorted on LeetCode 🔢👉👈 🧠 Key insight: Because the array is already sorted, we can avoid hash maps and use a two-pointer approach to find the target sum efficiently. ⚙️ Approach: 🔹Initialize two pointers at the start and end of the array 🔹Calculate the sum of values at both pointers 🔹If the sum is too large → move the right pointer left 🔹If the sum is too small → move the left pointer right 🔹Stop when the target is found ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #TwoPointers #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 18/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 1528. Shuffle String Used a direct indexing approach by placing each character at its correct position using the given indices array. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) A simple yet important problem to strengthen understanding of arrays and index mapping. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 35 – Plus One Worked on a problem where a large integer is represented as an array of digits, and the task was to increment the number by one. Key Learnings: Traversing arrays from right to left to simulate digit addition Handling carry when a digit becomes 10 Managing edge cases where all digits are 9 by creating a new array #DSA #Java #Arrays #ProblemSolving #CodingPractice #LeetCode
To view or add a comment, sign in
-
-
Day: 45/365 📌 LeetCode POTD: Special Binary String Hard Key takeaways/Learnings from this problem: 1. This one teaches that recognizing a balanced structure (like valid parentheses) inside a binary string is the real trick. 2. Big takeaway: recursion + sorting substrings smartly can turn a complex greedy-looking problem into something surprisingly elegant. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #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