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
Java LeetCode 101: Symmetric Tree Problem Solved
More Relevant Posts
-
🚀 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 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
-
-
✨ 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
-
-
Day 56 of #100DaysOfLeetCode 💻✅ Solved #205. Isomorphic Strings problem in Java. Approach: • Used two arrays to track character mappings for both strings • Traversed both strings simultaneously • Checked if the mapping values at current characters are equal • If not equal, returned false (mapping mismatch) • Updated both arrays with the current index + 1 • This ensures consistent one-to-one mapping between characters Performance: ✓ Runtime: 8 ms (Beats 72.19% submissions) ✓ Memory: 44.16 MB (Beats 22.15% submissions) Key Learning: ✓ Learned how to maintain mapping consistency between two strings ✓ Practiced using arrays for character indexing ✓ Strengthened understanding of string pattern matching problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #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
-
-
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
-
-
Just learned something that clicked for me today! 💡 The Frequency Counting Pattern in Java — one of the most used patterns in DSA! The idea is simple: → Use HashMap to count occurrences → Key = element, Value = count → One loop. Done. O(n)! HashMap<Integer, Integer> freq = new HashMap<>(); for (int num : arr) { freq.merge(num, 1, Integer::sum); } This single pattern helped me solve: ✅ Finding duplicates ✅ Most/least frequent element ✅ Character frequency in strings ✅ Two Sum Brute force = O(n²) 😴 HashMap pattern = O(n) 🚀 Still learning and loving every bit of it! Building a Banking System to practice all concepts 🏦 #Java #DSA #LearningInPublic #100DaysOfCode #JavaDeveloper #DataStructures #Programming
To view or add a comment, sign in
-
-
Day 68 of #100DaysOfLeetCode 💻✅ Solved #977. Squares of a Sorted Array problem in Java. Approach: • Traversed the array and squared each element • Used Arrays.sort() to sort the squared values • Returned the sorted array as the result Performance: ✓ Runtime: 10 ms (Beats 37.38% submissions) ✓ Memory: 47.98 MB (Beats 18.78% submissions) Key Learning: ✓ Practiced array transformation and sorting ✓ Learned how squaring affects order in sorted arrays ✓ Understood the importance of optimizing from O(n log n) to O(n) using two pointers Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #Sorting #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Today I solved “Fibonacci Number” on LeetCode using Java. 💡 Problem Summary The Fibonacci sequence is defined as: F(0) = 0 F(1) = 1 F(n) = F(n-1) + F(n-2) We need to compute F(n). 🧠 Approach I Used (Iterative Optimization) Instead of recursion (which is slow and redundant), I used an iterative approach: Maintain two variables → previous two values Keep updating them in a loop Build the answer step by step ⚙️ Why Not Recursion? Recursion leads to repeated calculations Time complexity becomes O(2ⁿ) ❌ Iterative solution reduces it to O(n) ✅ 📊 Complexity Analysis ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) ⚡ Result ✅ Accepted ⚡ Runtime: 0 ms (Beats 100%) 📚 Key Learning Always try to optimize recursion → iteration Use variables smartly to reduce space Even simple problems teach important optimization patterns Slowly building strong fundamentals, one problem at a time 💯 Day 15 done. Let’s keep the streak alive 🔥 #DSA #LeetCode #Java #100DaysOfCode #Algorithms #ProblemSolving #CodingJourney #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
Day 63 of #100DaysOfLeetCode 💻✅ Solved #2085. Count Common Words With One Occurrence problem in Java. Approach: • Iterated through each word in the first array • Avoided duplicate checks by ensuring each word is processed only once • Counted occurrences of the current word in both arrays • If the word appears exactly once in both arrays, incremented the result • Returned the final count Performance: ✓ Runtime: 88 ms (Beats 7.45% submissions) ✓ Memory: 46.06 MB (Beats 93.07% submissions) Key Learning: ✓ Practiced handling duplicates and frequency counting ✓ Improved understanding of string comparison in arrays ✓ Learned importance of optimizing nested loop solutions Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #Arrays #ProblemSolving #CodingJourney #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