Day 19 of my Data Structures & Algorithms journey. Today’s problem: Same Tree (Binary Tree recursion) on LeetCode. At first glance it looks simple, but it teaches an important idea: Two trees are identical only if both their structure and node values match at every level. Key concept practiced today: Depth-First Search (DFS) with recursion. Step by step the logic becomes: • If both nodes are null → trees match • If one node is null → trees differ • If values differ → trees differ • Otherwise → recursively check left and right subtrees Small problems like these quietly sharpen problem-solving muscles. Consistency > intensity. #LeetCode #DSA #Java #BinaryTree #CodingJourney
Mastering Binary Tree Recursion with LeetCode's Same Tree Challenge
More Relevant Posts
-
Day #10 / 100 — Data Structures & Algorithms Today’s focus was on array patterns and two-pointer techniques. Problems solved: • Maximum Subarray • Container With Most Water • Minimum Size Subarray Sum • Longest Substring Without Repeating Characters • 4Sum • Maximum Width Ramp • Boats to Save People Key takeaway: Many array problems reduce to a few core ideas — sliding window, two pointers, greedy choices, or prefix-based reasoning. Recognizing these patterns is gradually making problem-solving faster and more intuitive. #100DaysOfCode #DSA #LeetCode #Java #BackendDevelopment AccioJob
To view or add a comment, sign in
-
-
Day #13 / 100 — Data Structures & Algorithms Focused on Binary Search (answer space + edge cases) today. Problems solved: • Koko Eating Bananas • Find the Smallest Divisor Given a Threshold • Single Element in a Sorted Array • First Bad Version Key takeaway: Binary search is not just about finding an element — it’s about searching the answer space efficiently. What improved today: • Better handling of edge conditions • Clear understanding of low/high movement • Recognizing monotonic patterns faster Consistency is slowly converting concepts into instinct. #100DaysOfCode #DSA #LeetCode #Java #BackendDevelopment
To view or add a comment, sign in
-
-
Day #12 / 100 — Data Structures & Algorithms Focused on binary search (answer space) problems today. Problems solved: • Split Array Largest Sum • Capacity To Ship Packages Within D Days • Peak Index in a Mountain Array • Search in Rotated Sorted Array #100DaysOfCode #DSA #LeetCode #Java #BackendDevelopment
To view or add a comment, sign in
-
-
🚀 DSA Journey | Day 4 — Majority Element (LeetCode) Today, I solved the Majority Element problem and focused on improving my approach from a brute force solution to an optimized one. 🔹 🧠 Problem Understanding Given an integer array, the task is to find the element that appears more than ⌊n/2⌋ times. ✔ The problem guarantees that a majority element always exists ✔ Focus is on optimizing the approach efficiently 🔹 ⚙️ Approach 1: Brute Force For each element, I traversed the entire array again to count its frequency If the frequency exceeded n/2, I returned that element ❌ Time Complexity: O(n²) 👉 Works fine but not scalable for large inputs 🔹 ⚡ Approach 2: Optimized (Using HashMap) Stored frequency of elements using a HashMap Identified the element with count greater than n/2 ✔ Time Complexity: O(n) ✔ Space Complexity: O(n) 💡 Significant improvement compared to brute force 🔹 💡 Key Learnings ✔ How to optimize from O(n²) → O(n) ✔ Importance of choosing the right data structure ✔ Better understanding of frequency-based problems #DSA #LeetCode #Java #ProblemSolving #CodingJourney #Day4 #Learning #Algorithms
To view or add a comment, sign in
-
-
🚀 Day 48 of #100DaysOfCode Solved 295. Find Median from Data Stream on LeetCode 📊 🧠 Key Insight: We need to dynamically maintain numbers and efficiently return the median at any time. A naive approach (like maintaining a sorted list) works but is not optimal for large inputs. ⚙️ Approach Used (Sorted List + Binary Search): 1️⃣ Maintain a sorted list 2️⃣ Insert each incoming number at the correct position using Binary Search 3️⃣ For median: 🔹If size is odd → return middle element 🔹If even → return average of two middle elements ⏱️ Time Complexity: 🔹Insert: O(n) (due to shifting) 🔹Median: O(1) 📦 Space Complexity: O(n) #100DaysOfCode #LeetCode #DSA #Heaps #BinarySearch #Algorithms #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
Day 97/100 – LeetCode Challenge ✅ Problem: #105 Construct Binary Tree from Preorder and Inorder Traversal Difficulty: Medium Language: Java Approach: Recursive Construction with HashMap Lookup Time Complexity: O(n) Space Complexity: O(n) for map + recursion stack Key Insight: Preorder: [root, left subtree, right subtree] Inorder: [left subtree, root, right subtree] First element in preorder is always root Root's position in inorder splits left and right subtrees Solution Brief: Built HashMap to map inorder value → index for O(1) lookups. Maintained global index to track current root in preorder. Recursively built tree: Get root value from preorder at current index Find root position in inorder Build left subtree using elements before root Build right subtree using elements after root #LeetCode #Day97 #100DaysOfCode #Tree #BinaryTree #Java #Algorithm #CodingChallenge #ProblemSolving #ConstructBinaryTree #MediumProblem #Recursion #HashMap #DSA
To view or add a comment, sign in
-
-
🚀 **LeetCode Problem Solved – Max Consecutive Ones III** Today I solved **Problem 1004: Max Consecutive Ones III** using the **Sliding Window technique**. 🔹 **Problem Summary** Given a binary array `nums` containing 0s and 1s and an integer `k`, we are allowed to flip at most `k` zeros to ones. The goal is to determine the **maximum number of consecutive 1s** possible after performing at most `k` flips. 🔹 **Approach** Instead of checking every possible subarray, I used the **Sliding Window (Two Pointer) approach**: • Expand the window using the right pointer • Count the number of zeros in the window • If zeros exceed `k`, move the left pointer to maintain a valid window • Track the maximum window size 🔹 **Complexity** ⏱ Time Complexity: **O(n)** 💾 Space Complexity: **O(1)** 📊 **Result** ✔ 60 / 60 Testcases Passed ⚡ Runtime: **2 ms (Beats 99.93%)** Consistent practice with **Data Structures & Algorithms** helps build strong problem-solving skills and deeper understanding of algorithmic patterns. Always open to learning better approaches or optimizations! 💡 #LeetCode #DSA #Java #SlidingWindow #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 46 of #100DaysOfCode 💡 Problem Solved: Two Sum Today I worked on one of the most fundamental problems in Data Structures — finding two numbers in an array that add up to a target value. 🔍 Key Learning: Instead of using a brute-force approach (O(n²)), I used a HashMap to store elements and check complements efficiently, reducing the time complexity to O(n). 🧠 Takeaway: Using the right data structure can drastically improve performance. Hashing is powerful for quick lookups! #DataStructures #Algorithms #Java #ProblemSolving #LeetCode #CodingPractice #DSA #100DaysOfCode
To view or add a comment, sign in
-
-
Day 57/100 | #100DaysOfDSA ⛰️🔍 Today’s problem: Peak Index in a Mountain Array A perfect use-case of Binary Search on a pattern. Key observation: The array increases → reaches a peak → then decreases. Approach: • Use binary search on the index • Compare mid with mid + 1 • If arr[mid] > arr[mid + 1] → we are on the decreasing side → move left • Else → we are on the increasing side → move right This guarantees we always move toward the peak. Time Complexity: O(log n) Space Complexity: O(1) Big takeaway: Binary search isn’t just for sorted arrays — it works on patterns too. Recognizing these patterns is a game changer. 🔥 Day 57 done. #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearch #Arrays #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 5/100 – Data Structures & Algorithms Problems Solved: • Design Linked List • Rotate List • Intersection of Two Linked Lists • Minimum Index Sum of Two Lists • Remove Duplicates from Sorted List • Remove Duplicates from Sorted List II Concepts Practiced: • Linked List manipulation • Pointer traversal • Hashing for lookup optimization • Handling duplicates in sorted structures Key Learning: Working with Linked Lists improves understanding of pointer movement, node manipulation, and efficient traversal techniques. Staying consistent with daily problem solving while preparing for backend development roles. #100DaysOfCode #DSA #LeetCode #Java #BackendDevelopment
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