Day 43 of #100DaysOfLeetCode 💻✅ Solved #100. Same Tree problem in Java. Approach: • Used recursion to compare both binary trees simultaneously • If both nodes are null, returned true • If one node is null and the other is not, returned false • Checked whether the values of both nodes are equal • Recursively compared the left subtrees and right subtrees Performance: ✓ Runtime: 0 ms (Beats 100% submissions) 🚀 ✓ Memory: 43.10 MB (Beats 30.15% submissions) Key Learning: ✓ Practiced recursive traversal of binary trees ✓ Learned how to compare two trees node by node ✓ Strengthened understanding of tree recursion logic Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTrees #ProblemSolving #CodingJourney #100DaysOfCode
Solved #100. Same Tree problem in Java with recursive approach
More Relevant Posts
-
Day 47 of #100DaysOfLeetCode 💻✅ Solved #101. Symmetric Tree problem in Java. Approach: • Used recursion to compare the left and right subtrees of the root • If both nodes are null, the tree is symmetric at that level • If one node is null and the other is not, the tree is not symmetric • Compared the values of both nodes • Recursively checked left.left with right.right and left.right with right.left to verify mirror structure Performance: ✓ Runtime: 0 ms (Beats 100% submissions) ✓ Memory: 43.62 MB (Beats 48.60% submissions) Key Learning: ✓ Practiced mirror comparison in binary trees ✓ Learned how recursion can verify symmetry between two subtrees ✓ Strengthened understanding of tree traversal and structural comparison Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTrees #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 42 of #100DaysOfLeetCode 💻✅ Solved #704. Binary Search problem in Java. Approach: • Since the array is already sorted, applied the Binary Search algorithm • Initialized two pointers: left at the start and right at the end of the array • Calculated the middle index using (left + right) / 2 • If the middle element equals the target, returned the index • If the middle element is smaller than the target, moved the left pointer to mid + 1 • If the middle element is greater than the target, moved the right pointer to mid - 1 • Continued until the target was found or the search space became empty Performance: ✓ Runtime: 0 ms (Beats 100% submissions) 🚀 ✓ Memory: 48.32 MB (Beats 68.26% submissions) Key Learning: ✓ Practiced Binary Search with O(log n) time complexity ✓ Learned how pointer adjustments reduce the search space efficiently ✓ Strengthened understanding of searching algorithms in sorted arrays Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinarySearch #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
✨ DSA in Java – Day 83 🚀 Today I solved an interesting problem on Binary Trees: 👉 Sum of Root to Leaf Binary Numbers 🌱 What I Learned: How to traverse a binary tree using DFS (Depth First Search) Building numbers along the path using: ➤ current = current * 2 + node.val Identifying leaf nodes and calculating final values Improving recursion understanding in tree problems 💡 Approach: Start from root with value 0 At each node, update the current number If it's a leaf node → add it to the final sum Traverse left and right recursively 📌 Key Insight: Binary tree problems become easier when you think of them as path-based problems rather than node-based problems. 💻 Consistency is the key! Day by day, step by step, getting stronger in DSA 💪 #DSA #Java #BinaryTree #CodingJourney #LeetCode #100DaysOfCode #WomenInTech #Consistency
To view or add a comment, sign in
-
-
🚀 DSA in Java — Day 79 📌 Problem Solved: Sum Root to Leaf Numbers Today I solved the Sum Root to Leaf Numbers problem on LeetCode using Depth First Search (DFS) and Recursion. In this problem, each root-to-leaf path in a binary tree forms a number. The goal is to calculate the sum of all these numbers. 🔹 Approach Used: Used recursive DFS traversal Maintained a running number while moving from root to leaf At each step, updated the number using current = current * 10 + node.val When a leaf node is reached, added the number to the final sum 🔹 Key Concepts Practiced: ✔ Binary Trees ✔ Depth First Search (DFS) ✔ Recursion ✔ Tree Path Problems This problem improved my understanding of how recursion can be used to build values while traversing tree paths. Consistent practice is helping me become more comfortable with tree-based problems in DSA. #DSA #Java #BinaryTree #Recursion #LeetCode #CodingJourney #WomenInTech #100DaysOfCode
To view or add a comment, sign in
-
-
Day 44 of #100DaysOfLeetCode 💻✅ Solved Very Simple #169. Majority Element problem in Java. Approach: • Sorted the given array using Arrays.sort() • Observed that the majority element appears more than n/2 times • After sorting, the majority element will always be present at index n/2 • Returned the element at nums[n/2] Performance: ✓ Runtime: 7 ms (Beats 42.86% submissions) ✓ Memory: 55.96 MB (Beats 16.21% submissions) Key Learning: ✓ Understood how sorting can help identify the majority element ✓ Learned the property that the majority element always occupies the middle position after sorting ✓ Practiced array manipulation and problem solving in Java Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 51 of #100DaysOfLeetCode 💻✅ Solved #217. Contains Duplicate problem in Java. Approach: • Sorted the array using Arrays.sort() • Traversed the array starting from index 1 • Compared each element with its previous element • If any two adjacent elements are equal, returned true • If no duplicates are found, returned false Performance: ✓ Runtime: 24 ms (Beats 26.49% submissions) ✓ Memory: 76.56 MB (Beats 96.73% submissions) Key Learning: ✓ Practiced sorting-based approach for detecting duplicates ✓ Learned how sorting helps bring duplicate elements together ✓ Strengthened understanding of array traversal techniques Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 66 of #100DaysOfLeetCode 💻✅ Solved #3427. Sum of Variable Length Subarrays problem in Java. Approach: • Iterated through each index of the array • Determined the starting index using i - nums[i] • Ensured the start index does not go below 0 • Calculated sum of elements from start to current index i • Added each subarray sum to the total Performance: ✓ Runtime: 1 ms (Beats 99.90% submissions) ✓ Memory: 45.22 MB (Beats 56.30% submissions) Key Learning: ✓ Practiced handling variable-length subarrays ✓ Improved understanding of index-based range calculations ✓ Strengthened nested loop logic for array problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #PrefixSum #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 28 – LeetCode Practice Today I solved the "Path Sum" problem using Binary Trees and recursion in Java. The goal of the problem is to determine whether there exists a root-to-leaf path in a binary tree such that the sum of all node values in the path equals a given target sum. Approach I used: If the root node is null, return false. If the current node is a leaf node (no left and right child), check whether the targetSum is equal to the node value. Recursively call the function for the left and right subtree while subtracting the current node value from the targetSum. If any subtree returns true, it means a valid path exists. Key concept learned today: In tree recursion problems, reducing the target value at each step helps track the remaining sum required to reach the target. Consistency is more important than speed. Practicing a little every day is helping me understand recursion and tree traversal patterns better. #Day28 #LeetCode #DSA #Java #BinaryTree #CodingPractice
To view or add a comment, sign in
-
Day 45 of #100DaysOfLeetCode 💻✅ Solved Simple #268. Missing Number problem in Java. Approach: • Calculated the expected sum of numbers from 0 to n using the formula n(n+1)/2 • Traversed the array and calculated the actual sum of the elements • Subtracted the actual sum from the expected sum • The difference gives the missing number in the array Performance: ✓ Runtime: 0 ms (Beats 100% submissions) 🚀 ✓ Memory: 47.60 MB (Beats 29.84% submissions) Key Learning: ✓ Practiced using mathematical formulas to simplify problems ✓ Learned how sum comparison can help find a missing element efficiently ✓ Strengthened problem-solving skills with arrays Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 7/50 | #50DaysOfCode 📍 Platform: LeetCode 💻 Language: Java ✅ 167. Two Sum II - Input Array Is Sorted (Medium) Today’s problem focused on finding two numbers in a sorted array that sum up to a target. It helped reinforce the two-pointer technique and efficient array traversal. 🔎 Approach: Use two pointers: one at the start (left) and one at the end (right) of the array Calculate the sum of numbers at both pointers If sum equals target, return the 1-indexed positions [left+1, right+1] If sum < target, move left pointer forward If sum > target, move right pointer backward Continue until the solution is found 📌 Example: Input: numbers = [2,7,11,15], target = 9 Output: [1,2] Explanation: 2 + 7 = 9 → indices 1 and 2 This problem strengthened my understanding of two-pointer techniques, sorted arrays, and constant space solutions in Java. #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Consistency #LearningJourney #50DaysOfCode #LinkedIn
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