Day 75 of #100DaysOfCode Today I solved "Even Odd Tree" on LeetCode using Level Order Traversal (BFS). Key Idea: Each level of the tree must follow specific rules: Even-indexed levels (0, 2, 4...) • All values must be odd • Values must be in strictly increasing order Odd-indexed levels (1, 3, 5...) • All values must be even • Values must be in strictly decreasing order Approach: • Traverse the tree level by level using a queue (BFS) • Track the previous value for comparison • Validate both parity (odd/even) and ordering constraints Concepts Used: • Binary Trees • Breadth-First Search (BFS) • Level Order Traversal • Conditional validation Time Complexity: O(n) Space Complexity: O(n) This problem was a great mix of tree traversal + logical constraints, making it both tricky and fun Consistency is turning effort into skill. #Day75 #100DaysOfCode #LeetCode #BinaryTree #BFS #Cpp #CodingJourney
100DaysOfCode Day 75: LeetCode 'Even Odd Tree' Solution with BFS
More Relevant Posts
-
Day 31/75 🚀 Solved Maximum Twin Sum of a Linked List (LeetCode 2130) today! ✅ All 46/46 test cases passed ⚡ Runtime: 3 ms (Beats ~67%) 💾 Memory: 124.34 MB (Beats ~67%) 🔍 Approach: Converted the linked list into an array for easy access. ✔️ Stored all node values in a vector ✔️ Used two pointers → one at start, one at end ✔️ Calculated twin sum (list[i] + list[n-1-i]) ✔️ Tracked maximum among all pairs This avoids complex pointer manipulation. 💡 Key Learning: Sometimes extra space simplifies logic a lot. Choosing clarity over optimization can be a smart move. Consistency + smart decisions = efficient solutions 💡 #LeetCode #CPP #DSA #ProblemSolving #CodingJourney #75DaysOfCode #Focused
To view or add a comment, sign in
-
-
🚀 Day 62 of #100DaysOfCode 💻 Solved: Third Maximum Number (LeetCode 414) 🔍 Problem Statement: Given an integer array, return the third distinct maximum number. If it doesn’t exist, return the maximum number instead. 💡 Approach: The key here is “distinct” values — duplicates don’t count. First, focus on identifying unique numbers Then track the top 3 maximum distinct values If less than 3 distinct values exist → simply return the largest Instead of sorting (which adds extra cost), we can efficiently keep track of the top 3 values while traversing the array once. ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(1) (if done optimally) 📌 Key Learning: This problem teaches how to optimize by avoiding sorting and how to maintain multiple maximums efficiently in a single pass. #Day62 #LeetCode #DSA #CodingJourney #PlacementPrep
To view or add a comment, sign in
-
-
Day 12/30 – LeetCode Challenge Today’s problem: Minimum Distance Between Equal Elements (3740) Problem Overview We are given: - an array "nums" We need to: - find the minimum value of: 2 * (k - i) such that: - nums[i] = nums[j] = nums[k] - i < j < k If no such triplet exists, return -1. Approach I used a single optimized approach based on grouping indices: - store indices of each element using a map - for each unique number, we get all positions where it appears Then: - if the frequency is less than 3 → skip - otherwise, iterate through the index list and check consecutive triplets: - take (v[j], v[j+1], v[j+2]) - compute: 2 * (v[j+2] - v[j]) - keep updating the minimum answer Complexity - Time Complexity: O(n) - Space Complexity: O(n) Key Learning - derive a direct formula from index operations instead of brute force - be careful with loop boundaries even in simple logic YouTube Link: https://lnkd.in/gRnc3drP I’ve tried explaining this code. Would love to hear your valuable feedback! #LeetCode #Day12 #DSA #ProblemSolving #CPP #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 70 of #100DaysOfCode 📌 LeetCode Q3: 3Sum 💡 Problem: Find all unique triplets in the array which gives the sum of 0. 🧠 Approach I Used: - First, sorted the array - Fixed one element - Applied two-pointer technique for the remaining part - Skipped duplicates to avoid repeated triplets ⚡ Key Insight: Instead of brute force O(n³), using sorting + two pointers reduces it to O(n²) ❗ Edge Cases Handled: - Duplicate values - No valid triplets - Negative + positive mix ⏱ Complexity: - Time: O(n²) - Space: O(1) (excluding result) 🔥 Takeaway: Two-pointer + sorting = deadly combo for array problems 💯 💬 Open to feedback & better approaches! #Day70 #100DaysOfCode #LeetCode #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 8 / 100 Days of Code Challenge 💻🔥 Solved LeetCode 160 — Intersection of Two Linked Lists 🔗 🔍 Problem • Given two singly linked lists, find the node where they intersect • If no intersection exists, return null ⚙️ Approach (Two Pointer Switching) • Use two pointers starting at headA and headB • Traverse both lists simultaneously • When a pointer reaches the end, redirect it to the other list’s head 🔄 • Continue until both pointers meet • The meeting point is the intersection node (or null if no intersection) 💡 Key Learning • Equalizing path lengths without explicitly calculating them • Efficient pointer manipulation technique • Clean and optimal solution without extra space ⏱ Complexity • Time: O(n + m) ⏳ • Space: O(1) 📦 Consistency continues 🚀 #100DaysOfCode #LeetCode #DSA #LinkedList #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 22/75 🚀 Solved Determine if Two Strings Are Close (LeetCode 1657) today! ✅ All 169/169 test cases passed ⚡ Runtime: 6 ms (Beats ~75%) 💾 Memory: 23.30 MB (Beats ~94%) 🔍 Approach: First checked if both strings have equal length. Counted character frequencies using two arrays of size 26. Ensured: ✔️ Both strings use the same set of characters ✔️ Character frequency patterns can be rearranged to match If both conditions pass → strings are “close.” 💡 Key Learning: Understanding constraints and allowed operations helps simplify complex-looking problems. Here, it’s all about comparing character presence and frequency patterns, not actual character positions. Consistency + clarity = stronger problem-solving 💪 #LeetCode #CPP #DSA #ProblemSolving #CodingJourney #75DaysOfCode #Focused
To view or add a comment, sign in
-
-
Day 92/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 347 – Top K Frequent Elements(Medium) 🧠 Approach: Count the frequency of each element using a hashmap, then sort the elements based on frequency in descending order and pick the top k. 💻 Solution: class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: freq = {} for num in nums: freq[num] = freq.get(num, 0) + 1 sorted_items = sorted(freq.items(), key=lambda x: x[1], reverse=True) return [item[0] for item in sorted_items[:k]] ⏱ Time | Space: O(n log n) | O(n) 📌 Key Takeaway: Hashmaps combined with sorting provide a simple way to solve frequency-based problems, though heaps or bucket sort can optimize performance further. #leetcode #dsa #development #problemSolving #CodingChallenge
To view or add a comment, sign in
-
-
🚀 Day 65/100 – LeetCode Challenge. 🔍 Problem: Remove All Adjacent Duplicates in String. At first glance, this problem looks like a simple string manipulation task… but the real magic lies in using the right approach! 💡 Approach Used: Stack (via string) 👉 Idea: Traverse the string If current character = last character of result → remove it Else → add it 🧠 Key Insight: We simulate a stack using a string. Last added character = top of stack → result.back() ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(n) 📌 Takeaway: Whenever you see adjacent duplicate removal / pair cancellation, think of stack pattern instantly! 💬 Example: Input: "abbaca" Output: "ca" #Day65 #100DaysOfCode #DSA #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 45/100 – LeetCode Challenge 🔗 Problem: Linked List Components (LeetCode 817) 💡 Difficulty: Medium Today’s problem was all about understanding connected components in a linked list using a smart approach. 🧠 Key Insight: Instead of checking every possible combination, I used a HashSet for quick lookups. A component is counted only when a sequence ends, i.e., when the current node is in nums but the next node is not. ⚡ Approach: Convert nums into a set for O(1) lookup Traverse the linked list Count only when a component ends 📈 Time Complexity: O(n) 📦 Space Complexity: O(n) ✨ What I learned: Sometimes, solving problems efficiently is about identifying where something ends rather than where it starts. Consistency is key 🔥 Halfway through the journey — staying committed! #Day45 #100DaysOfCode #LeetCode #DataStructures #LinkedList #CodingJourney #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode Day 77/100 – Permutations 🧠 Problem: Given an array of distinct integers, return all possible permutations. 👉 Order matters here → [1,2,3] ≠ [3,2,1] 💡 Core Idea This is a classic Backtracking + Swapping problem 🔥 1️⃣ Fix one element at current index 2️⃣ Swap it with every possible element 3️⃣ Recursively generate permutations for remaining 4️⃣ Backtrack (swap back) 👉 Swap → Recurse → Undo 📚 Key Learnings 1. Backtracking with swapping technique 2. Generating all permutations efficiently 3. Understanding recursion tree deeply ⏱️ Complexity Time Complexity: O(n!) Space Complexity: O(n) (recursion stack) #100DaysOfCode #Day77 #LeetCode #DSA #Backtracking #Recursion #Algorithms #CodingJourney #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