🚀 [Day 13/30] Coding Challenge with @Educative.io 💻 💡 Problem: Connect All Siblings of a Binary Tree Today’s challenge was about linking every node in a perfect binary tree using a next pointer so that each node points to its immediate right sibling — and the last node of the tree points to null. I used a level-order traversal (BFS) to solve this cleanly. My approach: 1️⃣ Traverse the tree using a queue 2️⃣ Maintain a prev pointer to track the previously visited node 3️⃣ For every new node, set prev.next = current 4️⃣ Move prev forward and continue This way, nodes get connected from left to right across all levels, not just within the same level. ✨ Small win: Realizing that BFS already gives nodes in the exact order needed made the pointer linking feel natural and elegant. 🔍 Key Learnings: Level-order traversal is perfect for sibling connections A simple prev pointer can eliminate complex logic Tree problems often become easy when traversal order is correct #30DaysOfCode #Day12 #CodingChallenge #Educative #DSA #BinaryTree #BreadthFirstSearch #JavaScript #ProblemSolving #InterviewPrep #SoftwareEngineer #LearningInPublic #TechCareers #KeepCoding
Connect Binary Tree Siblings with BFS and Prev Pointer
More Relevant Posts
-
🚀 [Day 18/30] Coding Challenge with @Educative.io 💻 💡 Problem: Invert Binary Tree Today’s challenge was a classic tree problem — inverting a binary tree by swapping the left and right children of every node. The logic was simple yet powerful: 👉 Traverse the tree and swap left ↔ right at each node. I approached it using recursion: 1️⃣ Swap the left and right child 2️⃣ Recursively apply the same logic to both subtrees This can also be solved iteratively using BFS or DFS, but recursion keeps the solution very clean and readable. ✨ Small win: Problems like this remind me how elegant tree recursion can be — minimal code, clear intent. 🔍 Key Learnings: Tree transformations are often recursive by nature Preorder traversal works well for structural changes Simple problems still reinforce core fundamentals #30DaysOfCode #Day18 #CodingChallenge #Educative #DSA #BinaryTree #Recursion #Algorithms #JavaScript #ProblemSolving #InterviewPrep #SoftwareEngineer #LearningInPublic #TechCareers #KeepCoding
To view or add a comment, sign in
-
🚀 [Day 15/30] Coding Challenge with @Educative.io 💻 💡 Problem: Subarrays with K Different Integers Today’s challenge was a great exercise in sliding window + counting techniques. The goal was to count subarrays that contain exactly K distinct integers. The key insight that made this problem click: 👉 Counting “exactly K” is easier if we count (at most K) − (at most K − 1). My approach: 1️⃣ Used a sliding window with a frequency map to count subarrays with at most K distinct integers 2️⃣ Reused the same logic to compute at most (K − 1) 3️⃣ Subtracted the two results to get exactly K distinct subarrays This avoided nested loops and kept the solution in O(n) time. ✨ Small win: Turning a complex “exactly” condition into two simpler “at most” problems made the solution both elegant and efficient. 🔍 Key Learnings: Sliding window patterns are extremely powerful for subarray problems Breaking problems into reusable components simplifies logic “Exactly K” often hides a smart counting trick #30DaysOfCode #Day14 #CodingChallenge #Educative #DSA #SlidingWindow #HashMap #Algorithms #JavaScript #ProblemSolving #InterviewPrep #SoftwareEngineer #LearningInPublic #TechCareers #KeepCoding
To view or add a comment, sign in
-
Day 17 of 30-day Coding Sprint Today I’ve shifted focus to one of the most efficient techniques in a developer's toolkit: The Sliding Window. 3. Longest Substring Without Repeating Characters - The Challenge: Finding the length of the longest substring where every character is unique. A naive O(n^2) approach would be too slow for large strings. - The Strategy: Optimized Sliding Window Used a Frequency Hash Array (represented as a 256-element array) to store the last-seen index of each character. Two pointers, l (left) and r (right), define the current window. - The Optimization: Instead of moving the left pointer l one by one when a duplicate is found, I "jump" 1 directly to hash[s[r]] + 1. This ensures that the window always contains unique characters in the most efficient way possible. Result: A clean O(n) time complexity with a single pass through the string. Note: The sliding window isn't just about moving pointers; it's about maintaining a state (in this case, uniqueness) and shrinking or expanding the boundaries to satisfy that state. Using a hash array to store indices turns an O(n) "shrink" into an O(1) "jump." #30DaysOfCode #DSASprint #LeetCode #JavaScript #SlidingWindow #Optimization #Consistency
To view or add a comment, sign in
-
-
🚀 [Day 16/30] Coding Challenge with @Educative.io 💻 💡 Problem: Linked List Cycle Today’s challenge was about detecting whether a linked list contains a cycle — a classic problem that tests pointer logic. I used Floyd’s Cycle Detection Algorithm (Tortoise & Hare): 1️⃣ Move one pointer one step at a time 2️⃣ Move another pointer two steps at a time 3️⃣ If they ever meet → a cycle exists 4️⃣ If the fast pointer reaches null → no cycle This approach runs in O(n) time and O(1) space — clean and optimal. ✨ Small win: Realizing how pointer speed differences can expose cycles without extra memory is always satisfying. 🔍 Key Learnings: Cycle detection doesn’t need extra space Pointer manipulation is key in linked list problems Floyd’s algorithm is a must-know for interviews #30DaysOfCode #Day15 #CodingChallenge #Educative #DSA #LinkedList #TwoPointers #Algorithms #JavaScript #ProblemSolving #InterviewPrep #SoftwareEngineer #LearningInPublic #TechCareers #KeepCoding
To view or add a comment, sign in
-
🚀 [Day 13/30] Coding Challenge with @Educative.io 💻 💡 Problem: Schedule Tasks on Minimum Machines Today’s challenge was a classic interval scheduling problem — determining the minimum number of machines needed so that no tasks running on the same machine overlap. The moment I read the problem, I realized this was a greedy + sorting problem. My approach: 1️⃣ Sort all tasks by start time 2️⃣ Assign tasks to the current machine as long as they don’t overlap 3️⃣ Move overlapping tasks to a separate list for the next iteration (next machine) 4️⃣ Repeat this process until all tasks are assigned Each iteration represents one machine, so the number of iterations gives the minimum machines needed. ✨ Small win: Visualizing machines as “layers” of non-overlapping tasks made the greedy logic very intuitive. 🔍 Key Learnings: Sorting intervals is the first step in almost every scheduling problem Greedy allocation simplifies resource management problems Separating overlapping vs non-overlapping tasks reveals the minimum number of resources needed #30DaysOfCode #Day13 #CodingChallenge #Educative #DSA #Greedy #Scheduling #Intervals #JavaScript #ProblemSolving #InterviewPrep #SoftwareEngineer #LearningInPublic #TechCareers #KeepCoding
To view or add a comment, sign in
-
🚀 [Day 17/30] Coding Challenge with @Educative.io 💻 💡 Problem: Split Array Largest Sum Today’s challenge was an interesting mix of binary search + greedy validation. The goal was to split an array into m subarrays such that the largest subarray sum is minimized. The key insight: 👉 If we fix a maximum allowed subarray sum, we can greedily check whether the array can be split into at most m parts. My approach: 1️⃣ Set the search space between max(nums) and sum(nums) 2️⃣ Used binary search to guess the optimal maximum sum 3️⃣ For each guess, greedily counted how many subarrays were needed 4️⃣ Adjusted the search range based on feasibility This turned a complex optimization problem into a clean decision problem.| ✨ Small win: Realizing how “minimize the maximum” problems often map directly to binary search was a big confidence booster. 🔍 Key Learnings: Binary search isn’t just for sorted arrays Greedy checks pair perfectly with binary search Optimization problems often hide feasibility checks #30DaysOfCode #Day17 #CodingChallenge #Educative #DSA #BinarySearch #Greedy #Algorithms #JavaScript #ProblemSolving #InterviewPrep #SoftwareEngineer #LearningInPublic #TechCareers #KeepCoding
To view or add a comment, sign in
-
✨TypeScript's any vs unknown — Which one do you use? Most of us grab any for quick fixes, but it can hide bugs until runtime. unknown forces validation, making your code safer from the start. It's not about more typing. It's about writing smarter, more reliable code. 👉 Want the simple breakdown? I covered any, unknown, null, and undefined with clear examples here: https://lnkd.in/g9i8xSWr #TypeScript #WebDevelopment #ProgrammingTips #Coding #JavaScript #FullStackDevelopment
To view or add a comment, sign in
-
Day 8 of 30-day Coding Sprint Today’s focus was on a classic problem that teaches you why linear time isn't always good enough when dealing with exponents. Today's progress on LeetCode: 50. Pow(x, n) The Simple Recursive Approach: Multiplying x by itself n times. - Complexity: O(n) time. - The Issue: For large values of n, this hits the stack limit or simply takes too long. The Optimal Strategy: Binary Exponentiation (Divide & Conquer) - The Logic: Use the property (x^n) = (x^n/2)^2. By halving n at each recursive step, we drastically reduce the number of multiplications. The Result: O(log n) time. This turns a billion operations into roughly 30. #30DaysOfCode #DSASprint #LeetCode #JavaScript #Recursion #Math #Consistency
To view or add a comment, sign in
-
-
Just published a new technical write-up on LeetCode 1458: Max Dot Product of Two Subsequences. This one is a great example of how dynamic programming problems can look intimidating at first, but become manageable once you clearly define the state and transitions. It also highlights how handling negative values correctly can make or break a solution. I’m continuing to document my problem-solving process as part of my ongoing preparation and skills sharpening in software engineering. 📌 Read it here: https://lnkd.in/eXwn-TER Feedback and discussion are always welcome. #dsa #leetcode
To view or add a comment, sign in
-
🚀 Day 56 – Object-Oriented Concepts in JavaScript 📚 Sheryians Coding School Today was all about understanding Object-Oriented Programming (OOP) in JavaScript — a powerful way to write clean, reusable, and well-structured code. 🔑 What I learned today: What OOP means in JavaScript Objects and how they represent real-world entities Classes as blueprints for creating objects Constructors for initializing properties Prototypes for method sharing Basics of inheritance OOP helps in building scalable applications by organizing code into logical structures, making it easier to maintain and extend. ✨ Learned, practiced, and understood the fundamentals of OOP in JavaScript. Excited to apply these concepts in upcoming projects 💪 #Day56 #JavaScript #ObjectOrientedProgramming #WebDevelopment #LearningInPublic #SheryiansCodingSchool
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