Day 34 of #100DaysOfLeetCode 💻✅ Solved #110. Balanced Binary Tree on LeetCode using Java. Approach: • Used a bottom-up recursive approach to calculate height • Returned -1 immediately if any subtree is unbalanced • Compared left and right subtree heights at each node • Checked if the height difference is greater than 1 • Stopped early to optimize unnecessary computations Performance: ✓ Runtime: 0 ms (Beats 100.00% submissions) ✓ Memory: 45.33 MB (Beats 95.41% submissions) Key Learning: ✓ Understood how to combine height calculation with balance checking ✓ Learned early termination technique in recursion ✓ Improved problem-solving for tree-based recursive problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTree #Recursion #TreeProblems #ProblemSolving #CodingJourney #100DaysOfCode
Balanced Binary Tree Solved in Java on LeetCode
More Relevant Posts
-
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
-
-
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 98 - #100DaysOfCode Today’s problem was all about string comparison and operations simulation in Java. 💡 Problem Insight: Given a list of operations like "++X", "X++", "--X", "X--", we need to compute the final value of X after performing all operations. ⚠️ One key learning today: In Java, always use .equals() for string comparison instead of ==. Using == compares references, not actual content — a very common mistake! 🧠 Approach: Initialize x = 0 Traverse through each operation Increment or decrement based on the operation string 📌 What I Improved Today: Better understanding of string handling in Java Avoiding common pitfalls in comparisons Writing cleaner conditional logic #Java #CodingJourney #LeetCode #100DaysOfCode #ProblemSolving #Consistency
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 49 of #100DaysOfLeetCode 💻✅ Solved #387. First Unique Character in a String problem in Java. Approach: • Created an array of size 26 to store the frequency of each character • Traversed the string and counted how many times each character appears • Traversed the string again to find first character with frequency equal to 1 • Returned the index of that character • If no unique character is found, returned -1 Performance: ✓ Runtime: 6 ms (Beats 84.58% submissions) ✓ Memory: 47.16 MB (Beats 36.29% submissions) Key Learning: ✓ Practiced using frequency arrays for string problems ✓ Learned how counting characters helps find unique elements efficiently ✓ Strengthened understanding of string traversal and indexing Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #ProblemSolving #CodingJourney #100DaysOfCode
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 36 of #100DaysOfLeetCode 💻✅ Solved #111. Minimum Depth of Binary Tree on LeetCode using Java. Approach: • Used recursive approach to calculate minimum depth • Returned 0 when root is null (base case) • If one subtree is null, avoided taking minimum of 0 (handled edge case carefully) • Returned 1 + minimum depth of valid subtree • Ensured correct handling of skewed trees Performance: ✓ Runtime: 6 ms ✓ Memory: 82.20 MB Key Learning: ✓ Understood difference between minimum depth and maximum depth logic ✓ Learned importance of handling null subtree cases correctly ✓ Improved confidence in solving binary tree recursion problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTree #Recursion #TreeProblems #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 37/100 – LeetCode Challenge ✅ Problem Solved: 67. Add Binary 🟢 Difficulty: Easy 💻 Language: Java ⚡ Runtime: 1 ms (Beats 99.86%) Today’s problem was about adding two binary strings and returning their sum as a binary string. 🔎 Key Learning: Simulating binary addition manually (like elementary math addition) Handling carry properly Using StringBuilder for efficient string manipulation Traversing strings from right to left 🧠 Approach: Start from the last index of both strings Add digits along with carry Append sum % 2 to result Update carry as sum / 2 Reverse the result at the end 💡 Why this problem is important? It strengthens: String manipulation skills Understanding of number systems Edge case handling (different lengths, leftover carry) Consistency > Motivation. 37 days down, 63 to go! 💪🔥 #Day37 #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingJourney #SoftwareEngineering #DSA
To view or add a comment, sign in
-
-
Refactoring for Clarity: Array Manipulation in Java 👨💻 I’ve just finished a practical exercise on array manipulation. While the goal was simple (summing two arrays), I used it as an opportunity to apply improvements. - Method decomposition: Separated concerns into specialized methods (Read, Calculate, Display). - Input validation: Built a robust loop to handle invalid inputs and prevent crashes. - Data Formatting: Used printf to create a clear, readable results table. Small improvements in logic and organization make a huge difference in software quality. #Java #Algorithms #CleanCode #Backend #LearningToCode
To view or add a comment, sign in
-
-
Day 46 of #100DaysOfLeetCode 💻✅ Solved #374. Guess Number Higher or Lower problem in Java. Approach: • Used Binary Search to efficiently guess the number. • Calculated mid using low + (high - low) / 2 to avoid overflow. • Used the guess(mid) API to check if the number is higher, lower, or correct. • Updated the search range accordingly until the number was found. Performance: ✓ Runtime: 0 ms (Beats 100% submissions) 🚀 ✓ Memory: 41.68 MB (Beats 97.84% submissions) Key Learning: ✓ Practiced implementing binary search on a real problem ✓ Learned how to safely calculate mid to prevent integer overflow ✓ Strengthened problem-solving skills with search algorithms Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinarySearch #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