Day 84/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Recover Binary Search Tree A very interesting problem that tests your understanding of BST inorder properties. Problem idea: Two nodes in a BST are swapped by mistake. Recover the tree without changing its structure. Key idea: Inorder traversal of a BST should be sorted Why? • BST inorder traversal gives increasing order • If two nodes are swapped → order gets violated • Detect these violations to identify the wrong nodes How it works: • Perform inorder traversal • Track previous node (prev) • If prev.val > curr.val → violation found • First violation → mark first = prev • Second violation → mark second = curr • After traversal → swap values of first and second Optimization (used in your code): Use Morris Traversal to achieve O(1) space (no recursion/stack) Time Complexity: O(n) Space Complexity: O(1) (Morris Traversal) Big takeaway: Whenever working with BST, inorder traversal is your strongest tool. 🔥 Also, detecting anomalies in sorted order is a powerful technique. Day 84 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearchTree #MorrisTraversal #InorderTraversal #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
Yogesh ..’s Post
More Relevant Posts
-
Day 83/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Validate Binary Search Tree A core problem that tests your understanding of BST rules beyond just parent-child relationships. Problem idea: Check whether a given binary tree is a valid BST. Key idea: Maintain a valid range (min, max) for every node Why? • BST rule applies to the entire subtree, not just immediate children • Left subtree must be strictly less than root • Right subtree must be strictly greater than root • Each node must lie within its allowed range How it works: • Start with range (-∞, +∞) • For each node: • Check if value lies within (min, max) • Recursively validate left subtree with updated max = node.val • Recursively validate right subtree with updated min = node.val Time Complexity: O(n) Space Complexity: O(h) (recursion stack) Big takeaway: Never validate BST using only local checks — always think in terms of global constraints (ranges). 🔥 This pattern is extremely common in tree validation problems. Day 83 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearchTree #Recursion #TreeTraversal #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 77/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Binary Search Tree to Greater Sum Tree A clean and elegant BST transformation problem. Problem idea: Convert a BST so that each node’s value becomes the sum of all values greater than or equal to it. Key idea: Reverse inorder traversal (Right → Root → Left). Why? • In a BST, inorder gives sorted order • Reverse inorder processes nodes from largest to smallest • Maintain a running sum while traversing How it works: • Start from the rightmost node (largest value) • Keep a cumulative sum variable • Add current node value to sum • Update node value with sum • Move to left subtree Time Complexity: O(n) Space Complexity: O(h) (stack / recursion depth) Big takeaway: Whenever you need greater values accumulation in BST, think of reverse inorder traversal. 🔥 This pattern is very useful in BST transformation problems. Day 77 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearchTree #Trees #Recursion #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 65/100 | #100DaysOfDSA 🧩🚀 Today’s problem: N-Queens A classic hard backtracking problem. Problem idea: Place N queens on an N×N chessboard such that no two queens attack each other. Key idea: Use backtracking with efficient conflict checking. Why? • We must explore all valid board configurations • Reject placements that cause conflicts • Continue building only valid states How it works: • Place one queen per row • Track columns, diagonals, anti-diagonals • Use bit masking for faster checks ⚡ • Try placing → recurse → backtrack Optimization: Using bitmasks drastically reduces time compared to naive checking. Time Complexity: Exponential (but optimized with pruning) Space Complexity: O(n) recursion depth Big takeaway: Efficient state tracking (cols + diagonals) turns a brute-force problem into a much faster solution. 🔥 One of the most important backtracking problems to master! Day 65 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #Backtracking #Recursion #BitManipulation #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
The #SBOM accuracy problem: you don't know what you don't know. 🔍 Most SBOM tools scan your repository. Not your build. For C++ teams, that distinction matters. ➡️ What gets reported: every file in the repo, CI config, Java bindings, optional runtime dependencies ➡️ What was actually compiled: a fraction of that We ran a controlled test on OpenCV, same build, same commit, two tools, compared against verified ground truth. The methodology is fully reproducible on your own setup. Read the full breakdown 👉 https://lnkd.in/duPBdZ-A
To view or add a comment, sign in
-
-
Day 85/100 🚀 | #100DaysOfDSA Solved LeetCode 300 – Longest Increasing Subsequence (LIS) today. Initially, the brute force / DP approach (O(n²)) is intuitive, but I implemented the optimized O(n log n) solution using Binary Search. Approach (Patience Sorting Idea): Used an array tails[] where: • tails[i] = smallest possible tail of an increasing subsequence of length i+1 For each number: • Used binary search to find its correct position in tails • Replaced the element at that position • If it extends the largest subsequence → increased size ⚠️ Important: tails does NOT store the actual subsequence, but helps compute the length efficiently. Time Complexity: O(n log n) Space Complexity: O(n) Key takeaway: When you see “longest increasing subsequence”, think: • O(n²) → DP • O(n log n) → Binary Search + Greedy (optimal) This is a classic interview problem and a big step up from basic questions — good progress. #100DaysOfDSA #LeetCode #DSA #Java #DynamicProgramming #BinarySearch #Greedy #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 86 – Sorted List to Height-Balanced BST Today’s problem was about converting a sorted linked list into a height-balanced Binary Search Tree (BST). 💡 Key Idea: Use the slow & fast pointer technique to find the middle element of the linked list. The middle element becomes the root Left half → left subtree Right half → right subtree 🔁 Apply this recursively to build a balanced BST. 🧠 What I learned: How to simulate array-like access in a linked list Importance of finding the middle efficiently Recursion for tree construction 💻 Time Complexity: O(n log n) 💾 Space Complexity: O(log n) (recursive stack) #Day86 #DSA #Java #CodingJourney #LeetCode #BinaryTree #LinkedList
To view or add a comment, sign in
-
-
Day 82/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Lowest Common Ancestor of a Binary Search Tree A clean problem that shows the power of BST properties. Problem idea: Find the lowest common ancestor (LCA) of two nodes in a BST. Key idea: Use BST ordering to decide direction (no need to explore entire tree) Why? • In a BST: left < root < right • If both nodes are smaller → go left • If both nodes are greater → go right • Otherwise → current node is the LCA How it works: • Start from root • If p and q are both < root → move left • If p and q are both > root → move right • Else → you’ve found the split point (LCA) Time Complexity: O(h) Space Complexity: O(1) (iterative approach) Big takeaway: Whenever working with BST, always use its ordering property to optimize traversal. 🔥 This avoids unnecessary recursion and makes the solution super efficient. Day 82 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearchTree #TreeTraversal #LCA #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
🧠 Day 206 — Minimum Distance to Target 🎯📍 Today solved a simple yet important problem and did some revision alongside. 📌 Problem Goal Given an array, a target value, and a starting index: ✔️ Find the minimum distance between the start index and any index where the target exists 🔹 Core Idea Traverse the array and: ✔️ Check if current element matches the target ✔️ Calculate distance from the start index ✔️ Keep updating the minimum distance 🔹 Key Observation ✔️ Only indices with the target matter ✔️ Distance = absolute difference between indices ✔️ Simple linear scan gives optimal solution 🧠 Key Learning ✔️ Even easy problems strengthen fundamentals ✔️ Brute-force with clarity > overthinking ✔️ Absolute difference patterns are very common in arrays 💡 Today’s Realization Not every day needs to be a hard problem. Consistency with simple + revision days builds stronger intuition. 🚀 Momentum Status: Staying consistent and sharpening basics. On to Day 207. #DSA #Arrays #ProblemSolving #LeetCode #Java #CodingJourney #ConsistencyWins
To view or add a comment, sign in
-
Day 71/100 🚀 | #100DaysOfDSA Solved LeetCode 67 – Add Binary today. The problem was to add two binary strings and return their sum as a binary string. Approach: Simulated the manual binary addition process. • Used two pointers starting from the end of both strings • Maintained a carry variable • At each step: Added corresponding bits from both strings and the carry Appended (sum % 2) to the result Updated carry = sum / 2 • Continued until both strings are fully traversed and carry becomes 0 • Reversed the result at the end to get the correct order Time Complexity: O(max(n, m)) Space Complexity: O(max(n, m)) Key takeaway: Whenever dealing with number operations on strings, think in terms of digit-by-digit simulation from right to left, just like manual addition. #100DaysOfDSA #LeetCode #DSA #Java #Strings #Math #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 90/100 🚀 | #100DaysOfDSA Solved LeetCode 240 – Search a 2D Matrix II today. Approach: Used the top-right corner traversal (greedy + matrix property). Key observation: • Each row is sorted left → right • Each column is sorted top → bottom So: • Start at top-right corner • If current value > target → move left (col--) • If current value < target → move down (row++) • If equal → found This eliminates one row or column in each step. Time Complexity: O(m + n) Space Complexity: O(1) Key takeaway: For sorted 2D matrices, don’t jump to binary search immediately — sometimes a clever starting point (like top-right) gives a simpler linear solution. #100DaysOfDSA #LeetCode #DSA #Java #Matrix #BinarySearch #Greedy #ProblemSolving #Consistency
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