Day 30 of #100DaysOfLeetCode 💻✅ Solved #108. Convert Sorted Array to Binary Search Tree on LeetCode using Java. Approach: • Used Divide and Conquer strategy • Selected the middle element as the root to maintain balance • Recursively built the left subtree using left half of array • Recursively built the right subtree using right half of array • Ensured the tree remains height-balanced at every step Performance: ✓ Runtime: 0 ms (Beats 100.00% submissions) ✓ Memory: 45.18 MB (Beats 44.10% submissions) Key Learning: ✓ Understood how sorted arrays can directly map to balanced BST ✓ Strengthened recursion fundamentals in tree construction ✓ Improved understanding of height-balanced binary trees Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinarySearchTree #Recursion #DivideAndConquer #ProblemSolving #CodingJourney #100DaysOfCode
Java LeetCode 108: Convert Sorted Array to Balanced BST
More Relevant Posts
-
Day 33 of #100DaysOfLeetCode 💻✅ Solved #145. Binary Tree Postorder Traversal on LeetCode using Java. Approach: • Used recursion to perform postorder traversal • Followed Left → Right → Root order strictly • Traversed left subtree first • Then traversed right subtree • Added node value after visiting both subtrees Performance: ✓ Runtime: 0 ms (Beats 100.00% submissions) ✓ Memory: 43.12 MB (Beats 71.37% submissions) Key Learning: ✓ Clearly understood difference between preorder, inorder, and postorder ✓ Strengthened recursive tree traversal concepts ✓ Improved confidence in handling binary tree problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTree #Recursion #TreeTraversal #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 31 of #100DaysOfLeetCode 💻✅ Solved #94. Binary Tree Inorder Traversal on LeetCode using Java. Approach: • Used recursion to perform inorder traversal • Followed Left → Root → Right order strictly • Traversed left subtree first before processing current node • Stored node values in a list during traversal • Returned the final list after complete traversal Performance: ✓ Runtime: 0 ms (Beats 100.00% submissions) ✓ Memory: 42.76 MB (Beats 98.30% submissions) Key Learning: ✓ Strengthened understanding of tree traversal patterns ✓ Improved clarity on recursion stack behavior ✓ Reinforced difference between preorder, inorder, and postorder traversal Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTree #Recursion #TreeTraversal #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 32 of #100DaysOfLeetCode 💻✅ Solved #144. Binary Tree Preorder Traversal on LeetCode using Java. Approach: • Used recursion to perform preorder traversal • Followed Root → Left → Right order strictly • Added node value before traversing subtrees • Traversed left subtree first, then right subtree • Stored values in a list during traversal Performance: ✓ Runtime: 0 ms (Beats 100.00% submissions) ✓ Memory: 42.83 MB (Beats 96.77% submissions) Key Learning: ✓ Strengthened understanding of preorder traversal pattern ✓ Clearly differentiated preorder from inorder traversal ✓ Improved recursive tree traversal implementation skills Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTree #Recursion #TreeTraversal #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
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
To view or add a comment, sign in
-
-
Day 57 of #100DaysOfLeetCode 💻✅ Solved #506. Relative Ranks problem in Java. Approach: • Iterated through each player's score • Compared it with all other scores to determine its rank • Increased rank whenever a higher score was found • Assigned medals for top 3 ranks: Gold, Silver, Bronze • Converted remaining ranks to string and stored in result array Performance: ✓ Runtime: 124 ms (Beats 5.06% submissions) ✓ Memory: 46.76 MB (Beats 99.84% submissions) Key Learning: ✓ Understood ranking logic using comparison ✓ Practiced nested loop approach for problem solving ✓ Learned the importance of optimizing time complexity Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #Sorting #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 38 of #100DaysOfLeetCode 💻✅ Solved #222. Count Complete Tree Nodes problem in Java. Approach: • Used recursion to traverse the binary tree • Counted the current node and recursively counted nodes in left and right subtrees • Added the counts to get the total number of nodes • Returned 0 when the node is null to stop recursion Performance: ✓ Runtime: 0 ms (Beats 100% submissions) ✓ Memory: 44 MB Key Learning: ✓ Practiced recursion with binary trees ✓ Understood how tree traversal helps count nodes in a tree ✓ Improved recursive thinking while solving tree problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #ProblemSolving #CodingJourney #100DaysOfCode
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
-
-
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 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
-
Explore related topics
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