Approached this problem using recursion by traversing both left and right subtrees and keeping track of the maximum depth encountered. The idea is simple: Depth of a tree = 1 + max(depth of left, depth of right) This problem strengthened my understanding of tree traversal and recursive thinking. Consistent practice with tree problems to improve problem-solving skills step by step 🚀 #LeetCode #DataStructures #Java #BinaryTree #DSA #CodingJourney
Max Depth of Binary Tree via Recursion
More Relevant Posts
-
Day 41 – Longest Consecutive Sequence Solved a problem to find the length of the longest sequence of consecutive numbers in an unsorted array while maintaining O(n) time complexity. Key Learnings: Using a HashSet to efficiently check the presence of elements Identifying the start of a sequence by checking if the previous number exists Expanding the sequence to count consecutive numbers without sorting the array Optimizing the approach to avoid nested loops #DSA #Java #HashSet #Algorithms #ProblemSolving #CodingPractice
To view or add a comment, sign in
-
-
Today’s challenge was all about logic and boundary management. Solving the Spiral Matrix in Java isn't just about the code; it’s about visualizing how to traverse a 2D array while keeping track of four changing boundaries (top, bottom, left, right). It’s easy to get lost in the indices, but once the logic clicks, it feels like magic. These are the kinds of problems that sharpen the mind for the rigorous interviews at companies like Google and Microsoft. One step closer to the goal! 🚀 #DSA #Java #CodingJourney #SpiralMatrix #ProblemSolving #SoftwareEngineer #DataStructures #Algorithms
To view or add a comment, sign in
-
-
Problem of the Day 33 : Longest Cycle in a Directed Graph Solved a challenging graph problem where each node has at most one outgoing edge. Used a smart approach with a HashMap to track visit order and detect cycles efficiently. Learned how simple traversal + proper tracking can solve complex problems in O(V) time. #DSA #Graphs #Coding #ProblemSolving #Java
To view or add a comment, sign in
-
-
Every problem teaches something new — today it was LeetCode 50: Pow(x, n) At first, it looked simple: just calculate power. But the real challenge was optimizing it and handling edge cases like negative powers and Integer.MIN_VALUE overflow. Learned how Binary Exponentiation can turn an O(n) solution into O(log n) — that’s the beauty of algorithms! Moments like these remind me that problem-solving is not just about writing code, but thinking deeper. #LeetCodeJourney #DSA #KeepLearning #Java #ProblemSolving
To view or add a comment, sign in
-
-
`✅ LeetCode Top Interview 150 – Day 73 Today I solved a classic Binary Tree problem: Validate Binary Search Tree (BST). key idea : Start with range. • Left subtree nodes must be strictly smaller than the root • Right subtree nodes must be strictly greater than the root • Both subtrees must also follow the BST property recursively This problem strengthened my understanding of tree traversal and constraints propagation in recursive algorithms. #LeetCode #DSA #BinaryTree #BinarySearchTree #Java #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
-
Day 45/100 | #100DaysOfDSA 🚀🧩 Today’s problem: Remove All Occurrences of a Substring The task is simple: Given a string s and a substring part, keep removing the leftmost occurrence of part until it no longer exists in s. Approach: • Use StringBuilder for efficient modifications • Find the index of part using indexOf() • Delete that portion from the string • Repeat the process until part is no longer found Time Complexity: O(n × k) in worst case (where n is length of string and k is length of substring) Big takeaway: Sometimes the easiest solution is just repeating a simple operation until the condition disappears. Clean string manipulation problem today. 🔥 Day 45 done. #100DaysOfCode #LeetCode #DSA #Algorithms #Java #String #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Solved a matrix problem : checking whether one matrix can be obtained from another using rotations. At first it looked a bit tricky, but the key idea was simple: 👉 A 90° rotation can be done using transpose + reverse each row This makes the solution clean and efficient (O(n²)) and is a useful pattern to remember for similar problems. #DataStructures #Algorithms #DSA #Java #LeetCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
#Day58 of my second #100DaysOfCode Today’s problem was about carefully handling overlapping intervals. DSA • Solved Merge Intervals (LeetCode 56) • Implemented a brute force approach by checking and merging overlapping intervals → O(2n) + O(n log n) time • Implemented the optimal approach by sorting intervals and merging them in a single traversal → O(n log n) + O(n) time • Key idea: once intervals are sorted by start time, overlapping ranges can be merged efficiently in one pass These interval problems really test attention to detail with edge cases. #DSA #Algorithms #LeetCode #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
-
Another day another problem💪 In this problem, the array is sorted but rotated at an unknown pivot. Instead of using a linear search (O(n)), I applied a binary search strategy to maintain O(log n) time complexity. 💡 Key Learnings: Handling edge cases in rotated arrays Understanding how to calculate the real mid index after rotation Strengthening binary search fundamentals Consistent practice is helping me improve my problem-solving and DSA skills step by step. 💪 #LeetCode #DSA #BinarySearch #Java #Coding #ProblemSolving #SoftwareDeveloperJourney
To view or add a comment, sign in
-
-
70 LeetCode problems solved. Focused on building a strong foundation in Data Structures & Algorithms through consistent daily practice. Progress so far: • Covered core topics: Arrays, Strings, Recursion, Backtracking • Started solving medium-level problems regularly • Improving problem-solving approach and pattern recognition Approach: • Solve first, then analyze better solutions • Focus on patterns, not just individual questions Staying locked in on the process. #LeetCode #DSA #Java #ProblemSolving #Consistency
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