60 Days of Problem Solving Challenge - Day 27 👉 Today’s Problem: Vertical Tree Traversal (Binary Tree) The goal was to print the vertical order traversal of a binary tree from the leftmost vertical line to the rightmost. 💡 Approach / Logic: Used Level Order Traversal (BFS) with a queue. Assigned each node a Horizontal Distance (HD) from the root: Root → HD = 0 Left child → HD − 1 Right child → HD + 1 Stored nodes in a hashmap/dictionary where: HD → list of node values BFS ensures nodes in the same vertical line appear in level order. Finally, sorted the horizontal distances and printed values from leftmost to rightmost column. This problem reinforced concepts of Binary Trees, BFS traversal, and mapping nodes using horizontal distance. 📈 Progress Update 🔥 Current Streak: 27 Days 🎯 Goal: 60 Days of Consistent Problem Solving #60DaysOfCode #GeeksforGeeks #DSA #BinaryTree #ProblemSolving #Python #CodingJourney #Consistency
Binary Tree Vertical Traversal with BFS and Hashmap
More Relevant Posts
-
🗓 7 April 2026 🚀 LeetCode #703 – Kth Largest Element in a Stream Solved this problem using a clean and efficient Min Heap approach 🔥 💡 Instead of storing all elements, I maintained only the top K largest elements, which makes the solution scalable for large data streams. 🧠 Approach: • Created a min heap • Added elements in the constructor • If size exceeds k → removed the smallest element • In add(): – Push new value into heap – Pop if size exceeds k – Return the top element (Kth ) ⚡ Time Complexity: O(n log k) 📦 Space Complexity: O(k) 💭 Key Insight: We don’t need to store all elements — just maintain the top k elements. The smallest among them is the answer 🎯 #LeetCode #DSA #Python #Coding #100DaysOfCode #Heap
To view or add a comment, sign in
-
-
LeetCode Day 13 – Container With Most Water Today I solved the classic “Container With Most Water” problem — a great example of optimizing from brute force to an efficient solution! Problem Insight: We are given an array of heights, and we need to find two lines that together with the x-axis form a container that holds the maximum water. Approaches: Brute Force (O(n²)) Check all possible pairs Calculate area = width × min(height[i], height[j]) Keep track of maximum Optimal Approach – Two Pointer (O(n)) Start with two pointers at both ends Calculate area Move the pointer with smaller height inward Repeat until pointers meet Key Idea: The limiting factor is always the smaller height Moving the larger height won’t help increase area Complexity: Time: O(n) Space: O(1) What I learned: How two-pointer technique drastically reduces complexity Importance of understanding constraints before coding #LeetCode #Day13 #DSA #CodingJourney #Python #TwoPointers #ProblemSolving
To view or add a comment, sign in
-
-
Day 16/100 – DSA Challenge Solved: Convert a Number to Hexadecimal Today’s problem was a great exercise in bit manipulation and understanding how numbers are represented at a lower level. Key Learnings: Used bitwise operations (&, >>) to extract hexadecimal digits Handled negative numbers using 32-bit two’s complement Avoided built-in conversion functions to strengthen core logic This problem reinforced how powerful bit operations can be when working with number systems. Consistency is the goal — small progress every day adds up! #DSA #LeetCode #ProblemSolving #100DaysOfCode #Python #CodingJourney #SoftwareEngineering
To view or add a comment, sign in
-
-
🗓 7 April 2026 Solved LeetCode Problem #73 — Set Matrix Zeroes Approach 💡 Used a simple and clean strategy with sets: • Traverse the matrix and store rows & columns containing 0 • In the next pass, set those entire rows and columns to 0 Why this works: We avoid modifying the matrix while scanning, preventing incorrect propagation of zeroes. Time Complexity ⏱: O(n × m) Space Complexity 📦: O(n + m) Learnings 📚 • Importance of separating observation and modification phases • Clean use of sets for tracking state • Trade-off between space and simplicity Next goal 🚀 Optimizing this to O(1) space using the first row & column as markers #leetcode #dsa #python #codingjourney #100daysofcode
To view or add a comment, sign in
-
-
Happy to share 🛠️ my_mlir_track#6 Structured Control Flow (SCF) - for (Repo link: https://lnkd.in/gPE4Mrmk)! ✅ Induction Variables & Bounds: How to manage index types for loop control. ✅ Loop-Carried Variables: Using iter_args and scf.yield to maintain state across iterations. ✅ Python Integration: Compiling the logic into a shared library to bridge the gap between high-level orchestration and hardware-level execution. By utilizing this pipeline, we can generate highly optimized logic that remains easily accessible via a clean Python interface. (NOTE)Since I’ll be moving toward an assembly-like style in the next stage, I'm concluding the SCF series with this brief for loop entry. The next post will also be short; as the code becomes less "human-readable," keeping the content minimal should make it easier to digest. #LearningInPublic #Compiler #MLIR #SCF #for #C++ #HighPerformanceComputing
To view or add a comment, sign in
-
-
📈 Day 53 of #GeekStreak60 🧩 Today’s problem was about checking whether a matrix is a Toeplitz Matrix. 🧠 Core Idea Every element should match its top-left diagonal neighbor ↖️ If all such pairs match → the matrix is Toeplitz ✅ 💡 What I Did ➡️ Traversed the matrix starting from (1,1) ➡️ Compared each element with its top-left neighbor mat[i-1][j-1] 🔍 ➡️ Returned ❌ false immediately if any mismatch was found 📚 What I Learned ✨ Simple observations about patterns (like diagonals) can lead to clean and efficient solutions ✨ You don’t always need complex logic — sometimes local checks are enough! 🔥 Day 53 complete Consistency + clarity = growth 🚀 #GeekStreak60 #GeeksforGeeks #NPCI #Day53 #ProblemSolving #Python #CodingJourney
To view or add a comment, sign in
-
-
For computer architecture and assembly language course, I along with Musab Bin Majid, Umama Muhammad and Muhammad Asad Piracha worked on an N-body simulation. First it was implemented in python using a naive approach, it wasn't simple even in python but we got it worked out. Then came the real part, converting it into RISC-V assembly and then vectorizing most of the loops which after quite some time, worked. A lot of debugging, so many registers that we kept forgetting which one was for what purpose. We had to comment each and every line. The result... Much faster execution and easier to understand code. Now we move on to the hardest part; converting the Barnes-Hut algorithm which was made using the OctTree into assembly but first we will have to strip down the existing python file to basic simplistic syntax. Lets see where this leads us. #RISCV #Assembly #Python
To view or add a comment, sign in
-
-
🚀 Day 39/100 – LeetCode Challenge Today’s problem: 406. Queue Reconstruction by Height This problem focuses on applying a Greedy approach with sorting to reconstruct a queue based on height and positional constraints. 🔍 Key Insight: Sort people by height in descending order and k value in ascending order, then insert each person at their respective index. 💡 What I learned: Importance of sorting strategy in greedy problems How insertion at a specific index can maintain constraints Thinking from the perspective of "who affects whom" (taller vs shorter) 🧠 Approach: Sort the array → (-height, k) Insert each person at index k 💻 Code (Python): class Solution: def reconstructQueue(self, people): people.sort(key=lambda x: (-x[0], x[1])) queue = [] for p in people: queue.insert(p[1], p) return queue ⏱️ Time Complexity: O(n²) Consistency is the key — showing up every day and improving step by step. #Day39 #LeetCode #100DaysOfCode #DSA #Python #CodingChallenge #GreedyAlgorithm #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚀 Day 55 of #100DaysOfCode Solved LeetCode 350 – Intersection of Two Arrays II today! 🔍 Problem Insight: Given two arrays, we need to return their intersection such that each element appears as many times as it occurs in both arrays. 💡 Approach Used: - Used "Counter" (hash map) to store frequency of elements from first array - Traversed second array and matched elements - Reduced count after every match to handle duplicates correctly ⚡ Why this works: Efficient frequency tracking avoids nested loops and reduces time complexity. 🧠 Complexity: - Time: O(n + m) - Space: O(n) ✅ Key Learning: Hashing + frequency counting is powerful for problems involving duplicates and intersections. 🔥 Consistency is the key — showing up every day! #DSA #LeetCode #Python #CodingJourney #PlacementPrep #SoftwareEngineering #100DaysOfCode
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