🚀Day 33 of #100DaysOfCode 📌 LeetCode 110 – Balanced Binary Tree Today I solved the Balanced Binary Tree problem, which checks whether a binary tree is height-balanced. 👉 A binary tree is considered balanced if for every node, the height difference between its left and right subtrees is at most 1. 💡 Key Learning Instead of recalculating heights repeatedly (which is inefficient), I used a bottom-up DFS approach: Return the height of a subtree if it’s balanced Return -1 immediately if an imbalance is detected This helps in early stopping and keeps the solution optimal. ⚙️ Complexity Time: O(n) Space: O(h), where h is the height of the tree 🧠 Takeaway Optimizing recursive solutions by combining checks with return values can significantly improve performance and clarity. Consistency > Motivation 💪 On to the next problem! #LeetCode #DataStructures #BinaryTree #Python #CodingJourney #ProblemSolving #100DaysOfCode #LearningEveryDay
Balanced Binary Tree LeetCode Solution
More Relevant Posts
-
🚀 Day 41 / 200 Days of Code Solved the “Majority Element” problem on LeetCode today! 🔹 Problem: Find the element that appears more than ⌊n/2⌋ times in an array. 🔹 Constraint: Majority element is guaranteed to exist. 🔹 Approach Used: Python built-in optimization (max(set(nums), key=nums.count)) 🔹 Status: ✅ Accepted 🔹 Runtime: 0 ms 🔹 Memory: 21.07 MB (Beats 84.28%) While a simple built-in solution works, I also explored the Boyer–Moore Voting Algorithm, which solves it in O(n) time and O(1) space — a powerful technique frequently asked in interviews. 💡 Key Learning: Efficient problem-solving isn’t just about passing test cases — it’s about understanding optimized approaches and improving algorithmic thinking. Consistency > Motivation. One problem a day. Steady progress toward mastery. #Day41 #200DaysOfCode #LeetCode #Python #DataStructures #Algorithms #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 18 of #100DaysOfCode 📌 LeetCode 977 – Squares of a Sorted Array Today’s problem was about transforming a sorted array (with possible negative numbers) into a new array of squared values that remains sorted. 💡 Approach Used: Two Pointers Instead of squaring all elements and sorting again (O(n log n)), I applied the Two Pointer technique to compare absolute values from both ends and filled the result array from the back. 🧠 Key Learnings: ✔️ Importance of optimal thinking over brute force ✔️ How negative numbers affect sorting after squaring ✔️ Efficient use of Two Pointers in array problems ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) 🔍 Problem Pattern: Array + Two Pointers Consistency is the key — showing up every day and improving step by step! 💪 #Day18 #100DaysOfCode #LeetCode #DSA #Python #CodingJourney #BTech #DataStructures
To view or add a comment, sign in
-
-
✅ Day 64 of 100 Days LeetCode Challenge Problem: 🔹 #1784 – Check if Binary String Has at Most One Segment of Ones 🔗 https://lnkd.in/gpJYed9J Learning Journey: 🔹 Today’s problem focused on determining whether a binary string contains only one contiguous segment of '1's. 🔹 Since the string has no leading zeros, the first character is always '1'. 🔹 If a '1' appears again after a '0', it indicates the start of a second segment. 🔹 A single pass through the string is enough to detect this pattern. Concepts Used: 🔹 String Traversal 🔹 Pattern Detection 🔹 Conditional Logic Key Insight: 🔹 The pattern "01" followed by another '1' reveals multiple segments of ones. 🔹 Detecting this transition allows us to solve the problem efficiently. Complexity: 🔹 Time: O(n) 🔹 Space: O(1) 💬 What’s your favorite trick for solving binary string problems? #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers
To view or add a comment, sign in
-
-
✨ Day 8 of #GeekStreak60 Today’s Problem of the Day focused on determining whether two strings are Isomorphic. 🔍 Problem Statement Given two strings s1 and s2 of equal length, check whether they are isomorphic. Two strings are isomorphic if: • Each character in s1 maps to exactly one character in s2 • The mapping is consistent and preserves order • No two characters in s1 map to the same character in s2 💡 Approach ✔️ Compared the pattern of first occurrences in both strings ✔️ Used list comprehension with index() to capture structural patterns ✔️ Verified if both patterns match — ensuring isomorphism 🚀 Key Insight Instead of directly mapping characters, comparing structural patterns simplifies the solution and keeps the code clean and efficient. 🎯 Outcome Clean logic ➝ Minimal code ➝ Maximum clarity 📈 Progress Update Day 8 completed successfully! Consistency is the key to building strong problem-solving skills 💪 #GeeksforGeeks #GeekStreak60 #Day8 #ProblemSolving #Python #CodingJourney #NPCI
To view or add a comment, sign in
-
-
🚀 Day 41 of #100DaysofCode Challenge! Today’s focus was on recursion and backtracking patterns: 🔹 Generate Parentheses Solved this using a backtracking approach by building valid combinations incrementally while maintaining two constraints: The number of opening brackets used must not exceed n The number of closing brackets must not exceed the number of opening brackets This ensures only valid sequences are generated without checking invalid ones afterward. Core idea: Use recursion to explore all valid states Add '(' if openings < n Add ')' if closings < openings Key takeaways: ✔ Backtracking with constraint pruning ✔ Recursive state-space exploration ✔ Understanding how valid combinations grow systematically Time Complexity: O(4ⁿ / √n) (related to Catalan numbers) Space Complexity: O(n) for recursion stack Building stronger intuition for recursion and combinatorial problems every day 🚀 📸 Screenshots of solution are attached! #Day41 #DynamicProgramming #BinaryTree #TreeDP #Algorithms #ProblemSolving #Python #Java #CodingMindset #SoftwareEngineering #AdityaVerma #CodingJourney
To view or add a comment, sign in
-
-
🚀 #Day26 of #LeetCode Challenge 🧩 Problem Solved: 12. Integer to Roman Today’s problem was about converting a number into its Roman numeral representation. Sounds simple… but the tricky part is handling special cases like 4 (IV), 9 (IX), 40 (XL), 90 (XC), 400 (CD), and 900 (CM). 🔥 Key Learning: Instead of building logic digit by digit, I used a greedy approach: ✅ Create a mapping of values to Roman symbols ✅ Start from the largest value (1000 → 1) ✅ Keep subtracting while adding corresponding symbols ✅ Move downward This ensures we always build the Roman numeral in the correct order. ✔ All test cases passed Every day I’m realizing — most medium problems are about choosing the right pattern, not complicated logic. Consistency > Motivation 💯 Google #LeetCode #DSA #Python #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 𝗗𝗮𝘆 𝟭𝟳/𝟯𝟬 — 𝗗𝗦𝗔 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 Day 17 and I’ve officially entered tree territory 🌳 Binary trees feel very different from arrays and linked lists. Instead of moving linearly, the thinking branches out in multiple directions. It forces a shift from step-by-step logic to structured, recursive reasoning. Today was about getting comfortable with traversal patterns and trusting recursion a little more. 🔎 𝗗𝗮𝘆 𝟭𝟳 𝗙𝗼𝗰𝘂𝘀 • Practicing tree traversal techniques • Strengthening recursive problem solving • Solved: ✅ Maximum Depth of Binary Tree ✅ Invert Binary Tree ✅ Same Tree Recursion can look intimidating at first, but once the base case is clear, everything starts to feel surprisingly structured. Still building pattern recognition — one node at a time. On to Day 18 #DSA #Python #LeetCode #Consistency #SoftwareEngineering #ProblemSolving
To view or add a comment, sign in
-
🚀 LeetCode Practice: Problem #145 – Binary Tree Postorder Traversal I recently solved LeetCode 145, a classic tree traversal problem that strengthens understanding of Depth-First Search (DFS) and recursion. 📌 Problem Statement Given the root of a binary tree, return the postorder traversal of its nodes’ values. Postorder Traversal Order: 👉 Left → Right → Root 🧠 Technique Used: Depth-First Search (Recursive Approach) Approach Explanation: If the current node is None, return. Recursively traverse the left subtree. Recursively traverse the right subtree. Visit (append) the root node value at the end. This traversal ensures that child nodes are processed before their parent node. Time Complexity: O(n) Space Complexity: O(h) (Where h is the height of the tree due to recursion stack) #LeetCode #Python #DSA #ValidAnagram #ProblemSolving #Algorithms #DataStructures #CodingPractice #100DaysOfCode #InterviewPreparation #SoftwareEngineering #DeveloperJourney #TechCommunity #LearningByDoing
To view or add a comment, sign in
-
-
Hey everyone! Mahdi Shamlou here 🚀 I recently explored durable workflow engines in Python — something a lot of posts online don’t cover well in 2026. Here’s the quick rundown: ✨ Temporal – battle-tested, distributed, perfect for mission-critical workflows ⚡ DBOS Transact – lightweight, Postgres-backed, embedded durability 🐍 Prefect 3.x – Pythonic, open-source, great for data pipelines & automation 🛠️ Custom Python Engine – pure Python, full control, but tricky at scale 💡 My takeaway: For most projects, start with Prefect — durable, Pythonic, and minimal ops overhead. Use Temporal only when you really need ultra-long workflows or multi-language orchestration. Check out the full post here: https://lnkd.in/eCAkJq-M https://lnkd.in/eKYRR3pV Have you used any of these engines? How do you handle durable workflows in Python? Drop your thoughts below 👇 #programming #python #ai #workflows #designsystems
To view or add a comment, sign in
-
🚀 Day 29/181 — Optimization Mindset Today I revisited Group Anagrams and focused on improving my approach. ✅ Step 1 — Used defaultdict Learned the importance of defaultdict(list): Automatically initializes missing keys Cleaner and more Pythonic Reduces conditional checks ✅ Step 2 — Optimized the Solution Approach 1: Sorted each word and used it as a key. Time Complexity: O(N × K log K) Approach 2 (Optimized): Used character frequency count (26-size array) as the key. Converted it to a tuple for hashing. Time Complexity improved to: O(N × K) 🎯 Key Takeaway Solving a problem is good. Optimizing it is better. Understanding why it improves is best. One month of consistency completed. On to stronger patterns 💪🔥 #DSA #Optimization #HashMap #Python #LeetCode #CodingJourney #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