Day 86 of #100DaysOfCode Today I solved "Kth Smallest Element in a BST" on LeetCode using an Iterative Inorder Traversal (Stack). Key Idea: In a Binary Search Tree (BST), inorder traversal gives elements in sorted order. So the kth smallest element is simply the kth element in inorder traversal. Approach: • Use a stack to simulate inorder traversal • Traverse to the leftmost node first • Pop nodes one by one and decrement k • When k == 0, we’ve found our answer Concepts Used: • Binary Search Tree (BST) • Inorder Traversal • Stack • Iterative approach Time Complexity: O(h + k) Space Complexity: O(h) This problem shows how we can convert recursive traversal into an efficient iterative solution using a stack Understanding BST properties is really paying off now #Day86 #100DaysOfCode #LeetCode #BST #Stack #Cpp #CodingJourney
Kth Smallest Element in BST Solved with Iterative Inorder Traversal
More Relevant Posts
-
Day 104 of #200DaysOfCode Leveling up The grind continues — consistency in action. Today I solved "Kth Largest Element in an Array" on LeetCode using a Max Heap (Priority Queue) approach. Key Idea: The largest element can be efficiently accessed using a heap. By removing the top element k-1 times, we land on the kth largest element. Approach: • Build a max heap from the array • Pop the top element k-1 times • The top now represents the kth largest element Concepts Used: • Heap / Priority Queue • STL (C++) • Sorting Alternative Time Complexity: O(n log n) Space Complexity: O(n) Takeaway: Heaps are powerful when dealing with top K problems and can often replace full sorting for better clarity and efficiency. New day, new problem Consistency is becoming a habit #Day104 #200DaysOfCode #LeetCode #Heap #PriorityQueue #Cpp #CodingJourney #ProblemSolving #KeepGoing
To view or add a comment, sign in
-
-
Day 88 of #100DaysOfCode Today I solved "Construct Binary Search Tree from Preorder Traversal" on LeetCode using Recursion + Range Validation. Key Idea: In preorder traversal, elements are processed as: Root → Left → Right We can rebuild the BST by maintaining a valid range (lower, upper) for each node. Approach: • Start with range (-∞, +∞) • Pick current value → create node • For left subtree → range becomes (lower, root value) • For right subtree → range becomes (root value, upper) • Move index forward while constructing tree This ensures we build a valid BST without searching Concepts Used: • Binary Search Tree (BST) • Recursion • Preorder Traversal • Range constraints Time Complexity: O(n) Space Complexity: O(h) This problem shows how powerful range-based recursion can be for tree construction Understanding traversal patterns is unlocking new levels #Day88 #100DaysOfCode #LeetCode #BST #Recursion #Cpp #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 71 of #100DaysOfCode Today, I solved LeetCode 1572 – Matrix Diagonal Sum, a problem that focuses on matrix traversal and efficient computation. 💡 Problem Overview: Given a square matrix, the task is to calculate the sum of its primary and secondary diagonals, ensuring that the center element (if overlapping) is counted only once. 🧠 Approach: ✔️ Traversed the matrix to calculate: Primary diagonal → elements where row == column Secondary diagonal → elements where row + column == n - 1 ✔️ Handled the center element separately to avoid double counting ⚡ Key Takeaways: Understanding index relationships simplifies matrix problems Edge cases (like overlapping elements) are important Clean logic can avoid unnecessary loops 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(1) Small problems strengthen big concepts 🚀 #LeetCode #100DaysOfCode #DSA #Matrix #ProblemSolving #CodingJourney #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚀 Day 91/100 – 3Sum Closest 🧠 Problem: Given an array nums and a target, find 3 numbers such that their sum is closest to the target ✔️ Return the closest sum ✔️ Exactly one solution exists 💡 Core Idea 🔥 Sorting + Two Pointer 👉 Steps: 1. Sort the array 2. Fix one element 3. Use two pointers (left & right) 4, Move pointers based on sum 👉 Update closest sum whenever: abs(target - currentSum) is smaller 📚 Key Learnings 1. Two pointer pattern mastery 2. How to minimize difference (greedy thinking) 3. Handling closest value problems ⏱️ Complexity Time Complexity: O(n²) Space Complexity: O(1) #100DaysOfCode #Day91 #LeetCode #DSA #TwoPointers #Arrays #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 5️⃣ /15 — Consistency Challenge 🚀 Today’s problem: LeetCode 1855 — Maximum Distance Between a Pair of Values Solved using a clean two-pointer approach. 🔹 Problem Idea: We need to find the maximum value of j - i such that: i <= j nums1[i] <= nums2[j] Both arrays are non-increasing (sorted in descending order), which makes this a perfect two-pointer problem. 🔹 Approach (Two Pointers): Start two pointers: i = 0 for nums1 j = 0 for nums2 Traverse while both pointers are in bounds: If nums1[i] <= nums2[j] ✅ Valid pair found Update answer with j - i Move j forward to try for a larger distance Else (nums1[i] > nums2[j]) ❌ Invalid pair Move i forward to reduce nums1[i] and try to make condition valid 🔹 Time Complexity: Each pointer moves at most once through its array 👉 O(n + m) 🔹 Space Complexity: 👉 O(1) Clean logic, efficient solution, and another step in the consistency journey 💯 #LeetCode #DSA #TwoPointers #Consistency #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
Day 92 of #100DaysOfCode Today I solved "Balance a Binary Search Tree" on LeetCode using Inorder Traversal + Divide & Conquer. Key Idea: A balanced BST can be created from a sorted array. And guess what? Inorder traversal of a BST gives a sorted array Approach: • Perform inorder traversal → store values in a sorted array • Use divide & conquer: Pick middle element → make it root Left half → build left subtree Right half → build right subtree This ensures the tree remains height-balanced Concepts Used: • Binary Search Tree (BST) • Inorder Traversal • Recursion • Divide & Conquer Time Complexity: O(n) Space Complexity: O(n) This problem shows how combining two simple ideas can create a powerful solution From unbalanced → to optimized tree #Day92 #100DaysOfCode #LeetCode #BST #Recursion #Cpp #CodingJourney
To view or add a comment, sign in
-
-
📅 Day 270 – Bit Difference Calculation (Apr 3, 2026) ⚙️🔢 🔹 Problems Solved Today: 1️⃣ LeetCode 2220 – Minimum Bit Flips to Convert Number ⚙️ • Computed XOR of start and goal to identify differing bits. • Counted number of set bits in the result. • Each set bit represents one flip needed. • Used built-in bit count or Brian Kernighan’s algorithm. • Reinforced XOR + bit counting technique. 💡 Key Takeaways from Day 270: • XOR directly highlights differences between numbers. • Counting set bits is a fundamental bit manipulation skill. • Many transformation problems reduce to bit-level operations. 🔥 Consistency Update: ✅ Day 270 streak maintained. 🎯 1007 problems solved so far. #LeetCode #DSA #ProblemSolving #BitManipulation #Math #Consistency #Day270 🚀
To view or add a comment, sign in
-
-
🚀 Day 66 of #100DaysOfCode Today, I solved LeetCode 73 – Set Matrix Zeroes, a classic problem that tests in-place matrix manipulation and optimization techniques. 💡 Problem Overview: Given a matrix, if any cell contains 0, its entire row and column must be set to 0. The challenge is to perform this efficiently without using excessive extra space. 🧠 Approach: To solve this optimally, I focused on: ✔️ Using the first row and first column as markers ✔️ Tracking whether the first row/column initially contained zero ✔️ Updating the matrix in-place based on these markers This avoids using additional space and achieves optimal performance. ⚡ Key Takeaways: In-place algorithms help reduce space complexity Using matrix itself as storage is a powerful optimization trick Handling edge cases (first row/column) is critical 📊 Complexity Analysis: Time Complexity: O(n × m) Space Complexity: O(1) Improving problem-solving skills one day at a time 🚀 #LeetCode #100DaysOfCode #DSA #Matrix #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep
To view or add a comment, sign in
-
-
Opus Nerfed: If you faced degradation, here is what happened - Accuracy dropped from 83.3% → 68.3% (Rank #2 → #10), according to BridgeBench - Reasoning shrank (2200 → 600 chars) - Coding got “lazy” (less file reading before edits) - Worse performance during peak hours - Ignores context like project rules - More errors → more retries (higher API usage) Why this is happening - Reduced reasoning budget - Cost-cutting / fewer tokens - High GPU load handling - Faster responses over quality - Context processing trade-offs - Focus shifting to training newer models (like Mythos)
To view or add a comment, sign in
-
-
Day 170/365 – DSA Challenge 🚀 Solved Convert Sorted Array to Binary Search Tree on LeetCode today. 🔹 Problem: Given a sorted array, convert it into a height-balanced Binary Search Tree (BST). 🔹 Approach Used: Recursion (Divide & Conquer) Steps followed: 1️⃣ Pick the middle element of the array → root 2️⃣ Recursively build: Left subtree from left half Right subtree from right half 3️⃣ Repeat until subarray becomes empty 🔹 Key Idea: Choosing the middle element ensures balance of the BST. 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(log n) (recursion stack) 💻 Language: C++ A clean and elegant problem that strengthens BST properties + recursion intuition. #Day170 #365DaysOfCode #DSA #LeetCode #BinaryTree #BST #Recursion #CodingChallenge #Cpp
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