✅ LeetCode #297 – Serialize and Deserialize Binary Tree (Hard) Solved this classic binary tree problem using DFS (preorder traversal). 🔹 Implemented serialization by converting the tree into a string using recursion 🔹 Used a sentinel ("N") to represent null nodes 🔹 Deserialized the string back into the original tree structure with index-based DFS 🔹 Ensured correctness, readability, and optimal performance 💡 Key learnings: Importance of traversal order in tree reconstruction How recursion and state management work together Handling edge cases like null nodes effectively This problem strengthened my understanding of tree traversal, recursion, and system design concepts. #LeetCode #DataStructures #BinaryTree #Python #ProblemSolving #DSA #CodingJourney
LeetCode 297: Serialize and Deserialize Binary Tree with DFS
More Relevant Posts
-
🔥 Day 30 of #100DaysOfCode 📌 LeetCode 26 – Remove Duplicates from Sorted Array Today’s problem focused on in-place array manipulation and strengthening the two-pointer technique. 🧠 Problem Summary Given a sorted array, remove duplicates such that each unique element appears only once. Return the count of unique elements (k). Important: Do it in-place with O(1) extra space. 💡 Key Insight Because the array is already sorted, duplicates are always adjacent. So instead of checking all elements repeatedly: 👉 Compare current element with previous one. 👉 If different → place it at the next unique index. This is where the Two Pointer Approach shines: Pointer i → traverses array Pointer k → tracks position of next unique element 📊 Complexity ⏱ Time: O(n) 📦 Space: O(1) Consistency > Motivation 30 Days Done. Still going strong 💪 #Day30 #LeetCode #DSA #100DaysOfCode #Python #CodingJourney
To view or add a comment, sign in
-
-
LeetCode Problem 73: "Set Matrix Zeroes": Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's. You must do it in place. The below implementation in Python successfully resolves this problem in optimal way with constant space complexity. The logic is quite straightforward, use the first row and column as markers to determine whether the row or column contains zero inside or not. But before this traverse the first row and column to check whether they contain zeroes or not, store this result in a boolean variable. Now based on markers make the values of corresponding cells as zero. Time Complexity: O(m*n) #DSA #LeetCode #Python #OptimalSolution #Matrix #CompetitiveProgramming #ProblemSolving #CodingChallenge #Algorithms #Logic #DataStructures
To view or add a comment, sign in
-
-
𝗣𝘆𝘁𝗵𝗼𝗻 𝗗𝗮𝗶𝗹𝘆 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 | 𝗛𝗮𝗰𝗸𝗲𝗿𝗥𝗮𝗻𝗸 – 𝗧𝗲𝘅𝘁 𝗔𝗹𝗶𝗴𝗻𝗺𝗲𝗻𝘁 | 𝗗𝗮𝘆 𝟭𝟵 This Python problem tests patience more than logic. Day 19 of my Python Daily Challenge 🚀 Today’s challenge looked intimidating: 👉 Print a pattern 👉 Maintain symmetry 👉 Align text perfectly But the real difficulty wasn’t loops 👇 • Understanding rjust(), ljust(), center() • Breaking the problem into visual sections • Debugging spaces, not code 😅 💡 𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄 𝗽𝗮𝘁𝘁𝗲𝗿𝗻 𝗳𝗿𝗼𝗺 𝗗𝗮𝘆 𝟭𝟵: Some problems aren’t about algorithms. They’re about 𝗽𝗿𝗲𝗰𝗶𝘀𝗶𝗼𝗻 𝗮𝗻𝗱 𝘀𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗲. If you can control spacing, you can control output. Be honest — do pattern problems test your patience too? 👇 #Python #HackerRank #DailyCoding #ProblemSolving #InterviewPrep #LearnInPublic #Consistency
To view or add a comment, sign in
-
-
LeetCode | Pow(x, n) ⚡ We compute x^(n/2) once and reuse it, reducing time from O(n) to O(log n). 🔹 Approach: Binary Exponentiation 🔹 Key idea: Reuse half power using divide & conquer 🔹 Time Complexity: O(log n) 🔹 Space Complexity: O(log n) recursion stack Daily DSA practice to improve algorithmic thinking 🚀 #LeetCode #DSA #Recursion #DivideAndConquer #Python #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
LeetCode Problem 83: Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. The below implementation in Python successfully resolves this in time complexity of O(n) where n is length of the list with constant space complexity. The approach is simple, handle the base case first like list having 0 or 1 number of nodes and then write the logic of handling lists of length greater than one. Maintain two pointers, one to keep track of present node and other to keep track of previous node. Check if the value of both nodes match or not, if match update the pointing of previous node, point its next to the present.next. #LeetCode #LinkedList #Python #CompetitiveProgramming #Algorithms #DataStructures #ProblemSolving
To view or add a comment, sign in
-
-
🔥 Day 96 — #100DaysOfLeetCode ✅ Problem: Binary Number with Alternating Bits (Easy) Today’s challenge was to check whether a given integer’s binary representation has alternating bits — meaning no two adjacent bits are the same. 🧠 Approach: Convert number to binary. Check if it contains "11" or "00". If yes → not alternating. Otherwise → valid alternating pattern. ⚡ Example n = 5 → binary = 101 → ✔ alternating ⏱ Complexity Time: O(k) Space: O(1) (k = number of bits) #LeetCode #DSA #CodingChallenge #Python #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 56 — LeetCode 451: Sort Characters by Frequency using HashMap + Sorting. 💡 Key Learnings: • Counting character frequency using dictionary • Custom sorting with key=lambda • Efficient string building using "".join() • Understanding time vs space complexity trade-offs ⏱️ Complexity: Time — O(n + k log k) Space — O(k) #Day56 #LeetCode #Python #DataStructures #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
#Day - 32 LeetCode #334 – Increasing Triplet Subsequence (Medium) In this problem, the goal was to determine whether an array contains an increasing triplet subsequence in O(n) time and O(1) space complexity. 🔹 Approach Used: Maintained two variables (first and second) initialized to infinity. Iterated through the array once. Updated first and second dynamically. Returned True when a valid third element was found. This problem strengthened my understanding of: ✅ Greedy algorithms ✅ Optimized space complexity ✅ Efficient single-pass solutions ✅ Logical thinking for edge cases Under the Guidance of : Rudra Sravan kumar #LeetCode #ProblemSolving #Python #DataStructures #Algorithms #CodingJourney #SoftwareDeveloper
To view or add a comment, sign in
-
-
Day 45 – Splitting and Joining a String: Today’s task focused on splitting a string using a user-defined delimiter and then joining the parts back into a clean, readable format. This exercise strengthened understanding of string methods, input handling, and text restructuring, which are essential skills for data preprocessing and text manipulation in real-world applications. GitHub Code: https://lnkd.in/gznh5VpR #Day45 #100DaysOfCode #Python #StringManipulation #LogicBuilding #TextProcessing #DailyCoding #Consistency
To view or add a comment, sign in
-
-
This solution solves LeetCode 3013: Divide an Array Into Subarrays With Minimum Cost II by applying a sliding window technique with balanced data structures to efficiently track the smallest possible starting elements. Since the first subarray always begins at index 0, its cost is fixed, and the problem reduces to selecting the remaining k−1 starting indices within the given distance constraint such that their values sum to the minimum. By continuously maintaining the smallest k−1 elements as the window moves, the approach achieves optimal performance and avoids time-limit issues common with brute-force methods. #LeetCode #HardProblem #Python #SlidingWindow #DataStructures #Algorithms #CompetitiveProgramming #CodingInterview #Optimization
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