Solved one of the classic Binary Tree problems on LeetCode: Validate Binary Search Tree. At first glance, the problem seems straightforward just check if left <root< right. But the real challenge is ensuring that every node respects the global BST constraints, not just its immediate parent. Problems like this remind me how important it is to think beyond local conditions and consider global invariants in tree structures. #LeetCode #DataStructures #Java #BinaryTree #DSA #ProblemSolving #CodingJourney
Birender Pal Singh’s Post
More Relevant Posts
-
Solved LeetCode Problem 46 – Permutations ✅ The idea is pure backtracking with swapping. At each index, I fix one element and recursively generate permutations for the remaining part of the array. By swapping the current element with every possible choice and then swapping back, I explore all valid arrangements without extra space. Once the index reaches the end, the current array represents one complete permutation. A classic example of how recursion + backtracking systematically explores all possibilities 🚀 #LeetCode #DSA #Backtracking #Recursion #ProblemSolving #Java
To view or add a comment, sign in
-
-
Solved "Container With Most Water" on LeetCode today using the Two-Pointer Technique. 🚀 The key insight is that the area formed by two lines depends on the shorter height and the distance between them. Starting with pointers at both ends of the array, we compute the area and move the pointer at the smaller height inward to potentially find a taller boundary and maximize the area. This approach efficiently reduces the problem from O(n²) brute force to O(n) time with O(1) space. Problems like this are a great reminder that the right observation can drastically optimize a solution. 💡 #LeetCode #DSA #TwoPointers #Java #ProblemSolving
To view or add a comment, sign in
-
-
Day: 57/365 📌 LeetCode POTD: Special Positions in a Binary Matrix Easy Key takeaways/Learnings from this problem: 1. This one shows how precomputing row and column counts makes checking each cell super easy. 2. Instead of re-scanning the whole row and column every time, count once and reuse smartly. 3. Good reminder that brute force can often be optimized with a tiny bit of preprocessing. 4. Clean implementation and careful condition checking matter more than complex algorithms here. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
-
🚀 Day 15 of #100DaysOfCode Solved Reverse Linked List on LeetCode 🔄🔗 🧠 Key insight: Reversing a linked list is all about careful pointer manipulation. By tracking prev, current, and next, we can reverse links in-place without extra memory. ⚙️ Approach: 🔹Initialize prev = null, current = head 🔹Store next node before breaking the link 🔹Reverse current.next to point to prev 🔹Move pointers forward until the list ends ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #LinkedList #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 18 of #100DaysOfCode Solved Remove Duplicates from Sorted List II on LeetCode 🔗 🧠 Key insight: When duplicates appear in a sorted linked list, we need to remove all occurrences, not just one. Using a dummy (sentinel) node makes it easier to handle cases where duplicates start at the head. ⚙️ Approach: 🔹Create a dummy node pointing to the head 🔹Traverse the list with two pointers 🔹If a duplicate sequence is found, skip the entire block 🔹Otherwise, move forward normally ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #LinkedList #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
Day 13/100 – LeetCode Challenge Problem: Linked List Cycle Today’s problem was about detecting whether a cycle exists in a linked list. Approach: Used Floyd’s Cycle Detection Algorithm (Tortoise and Hare). slow pointer moves one step fast pointer moves two steps If a cycle exists, both pointers will eventually meet If fast reaches null, the list has no cycle Complexity: Time: O(n) Space: O(1) Concepts Practiced: Linked List traversal Two-pointer technique Cycle detection algorithm #100DaysOfCode #LeetCode #DSA #Java #LinkedList #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 7/100 – LeetCode Challenge Problem: Palindrome Number Today’s problem focused on number manipulation without converting the integer into a string. Approach: If number is negative → return false Reverse the digits using modulo (% 10) and division (/ 10) Compare reversed number with original number Logic Used: Extract last digit: rem = x % 10 Build reversed number: rev = rev * 10 + rem Remove last digit: x = x / 10 Complexity: Time: O(log₁₀ n) Space: O(1) Key takeaway: Problems involving digits can often be solved mathematically without string conversion. #100DaysOfCode #LeetCode #DSA #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 20/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 350. Intersection of Two Arrays II Used sorting + two-pointer technique to efficiently find common elements appearing in both arrays while maintaining correct frequency. ⏱️ Time Complexity: O(n log n + m log m) 📦 Space Complexity: O(min(n, m)) (for storing the intersection) Strengthening understanding of array traversal and two-pointer pattern through consistent practice. 💪 Consistency keeps the progress moving 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
LeetCode Problem || Check if Binary String Has at Most One Segment of Ones(1784)🚀 we need to check: The string should have only one continuous block of '1's. After a '0' appears, '1' should never appear again. ✨ Insight: Instead of manually counting segments using loops, we can simply check if "01" exists in the string. 📌 Time Complexity: O(n) Practicing problems like these helps improve pattern recognition and problem-solving efficiency. #LeetCode #DSA #Java #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 23/100 – LeetCode Challenge Today’s problem: Partitioning Into Minimum Number of Deci-Binary Numbers 🔹 Key Insight: The minimum number of deci-binary numbers required is equal to the maximum digit present in the string. 🔹 Approach: Traverse through each character in the string Convert it to integer (ch - '0') Track the maximum digit Return the maximum value 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(1) ✨ Simple logic, but powerful observation! Instead of constructing numbers, we just analyze the digits. Consistency > Motivation 💪 #Day23 #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingJourney
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