Day 35/100 | #100DaysOfDSA 🌳💻 Today’s problem: Same Tree The goal is to determine whether two binary trees are identical — meaning they have the same structure and the same node values. Approach: • Use recursion to traverse both trees simultaneously • If both nodes are null → they match • If one node is null and the other isn’t → trees are different • If node values differ → trees are different • Recursively check the left and right subtrees Both trees must match at every node for them to be considered the same. Time Complexity: O(n) Space Complexity: O(h) (recursion stack) Big takeaway: When comparing two trees, traverse them in parallel and validate structure and values at each step. Simple logic, but a great exercise for strengthening recursive tree thinking. One more tree pattern learned. 🚀 #100DaysOfCode #LeetCode #DSA #BinaryTree #Trees #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity #SoftwareEngineer #Consistency #Programmers #TechGrowth
Yogesh ..’s Post
More Relevant Posts
-
🔥 𝗗𝗮𝘆 𝟴𝟭/𝟭𝟬𝟬 — 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲 𝟳𝟴. 𝗦𝘂𝗯𝘀𝗲𝘁𝘀 | 𝗠𝗲𝗱𝗶𝘂𝗺 | 𝗝𝗮𝘃𝗮 Given an integer array, return all possible subsets (the power set) — no duplicates allowed. 𝗠𝘆 𝗮𝗽𝗽𝗿𝗼𝗮𝗰𝗵 — 𝗕𝗮𝗰𝗸𝘁𝗿𝗮𝗰𝗸𝗶𝗻𝗴: ✅ At each index, make a choice: include or exclude ✅ Recurse with the element added → then backtrack (remove it) ✅ Recurse again without the element ✅ Base case: when index == nums.length, save the current subset This explores every branch of the decision tree, giving us all 2ⁿ subsets cleanly. 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆: ⏱ Time: O(n × 2ⁿ) — 2ⁿ subsets, each copied in O(n) 📦 Space: O(n) recursion depth Backtracking is one of those patterns that feels magical once it clicks — the "add → recurse → remove" rhythm is the heart of so many classic problems. 📂 𝗙𝘂𝗹𝗹 𝘀𝗼𝗹𝘂𝘁𝗶𝗼𝗻 𝗼𝗻 𝗚𝗶𝘁𝗛𝘂𝗯: https://lnkd.in/gZmezt_g 19 more days to go. Almost there! 💪 #LeetCode #Day81of100 #100DaysOfCode #Java #DSA #Backtracking #Recursion #CodingChallenge #Programming
To view or add a comment, sign in
-
Day 36/100 | #100DaysOfDSA 🌳💻 Today’s problem: Subtree of Another Tree The task is to determine whether one binary tree is a subtree of another. A subtree must match both the structure and node values of the original tree. Approach: • Traverse the main tree using recursion • At each node, check if the subtree rooted there matches the given subRoot • Use a helper function to compare both trees for structural and value equality • If no match is found, continue checking the left and right subtrees This works by combining two recursive checks: 1️⃣ Search for a potential matching root 2️⃣ Verify if both trees are identical Time Complexity: O(n × m) Space Complexity: O(h) Big takeaway: Complex tree problems often break down into combining simpler tree problems — in this case, tree traversal + same tree comparison. Building stronger tree problem-solving patterns every day. 🚀 #100DaysOfCode #LeetCode #DSA #BinaryTree #Trees #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity #SoftwareEngineer #Consistency #Programmers #TechGrowth
To view or add a comment, sign in
-
-
LeetCode Problem #1920 – Build Array from Permutation Today I solved an interesting array problem that helped me understand indexing and array traversal better. 📌 Problem: Given a 0-indexed array `nums`, build a new array `ans` such that: `ans[i] = nums[nums[i]]` 📌 Approach: * Create a new array `ans` with the same length as `nums` * Traverse the array using a `for` loop * For each index `i`, access the value `nums[i]` * Use that value as an index again to get `nums[nums[i]]` * Store the result in `ans[i]` 📌 Key Concepts Practiced: ✔ Array traversal ✔ Nested indexing ✔ Understanding how values can act as indexes 📌 Time Complexity: O(n) – since we traverse the array only once. 📌 Key Takeaway: Sometimes the value inside an array can also represent an index, and understanding this idea helps solve many array-based problems efficiently. 💡 Learning Note This problem improved my understanding of **index-based operations and array manipulation**, which are fundamental concepts for solving many coding interview questions. #LeetCode #CodingPractice #Java #DSA #Arrays #ProblemSolving
To view or add a comment, sign in
-
-
Day 62/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Combination Sum Classic backtracking problem. Problem idea: Find all unique combinations where numbers sum up to a target. Each number can be used unlimited times. Key idea: Use backtracking (choose → explore → backtrack). Why? • We need to explore all possible combinations • Stop when sum exceeds target • Add result when sum == target How it works: • Pick a number • Stay on same index (reuse allowed) • Move forward when skipping • Backtrack to try other paths Time Complexity: Exponential (depends on combinations) Space Complexity: O(target) recursion depth Big takeaway: Backtracking is all about exploring choices and undoing them efficiently. This pattern is super important for recursion problems. 🔥 Day 62 done. #100DaysOfCode #LeetCode #DSA #Algorithms #Backtracking #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
🚀Solved Validate Stack Sequences by simulating the stack using a simple array instead of relying on built-in stack classes. This helped reduce overhead and kept the operations efficient. Focused on writing clean logic with optimal time complexity. 😊 Result: 💯 Achieved 0 ms runtime beating 100% of submissions, with memory usage around 45.52 MB performing in the top percentile. 💥 #LeetCode #DSA #Java #Coding #ProblemSolving #Preparation #Anurag_University 🚀🚀
To view or add a comment, sign in
-
-
🚀 #60DaysOfLeetCode – Day 32 Today’s problem was about removing all adjacent duplicates in a string. 🔹 Approach Used: Stack To efficiently handle consecutive duplicates, I used a stack-based approach: Traverse the string character by character. If the stack is not empty and the top element matches the current character, pop it (this removes the duplicate pair). Otherwise, push the current character onto the stack. Finally, build the result string from the stack and reverse it to maintain the correct order. 🔹 Key Learning: Using a stack helps simulate the process of removing adjacent duplicates in a single pass, achieving O(n) time complexity and avoiding unnecessary reprocessing. This problem highlights how stacks are powerful for handling sequential patterns and cancellations, especially in string manipulation problems. On to Day 33! 💻🔥 #LeetCode #DSA #Java #CodingChallenge #ProblemSolving #LearningInPublic #60DaysOfCode
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟑𝟑 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on generating all unique subsets when the array contains duplicate elements. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Subsets II 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 • First, sorted the array to group duplicate elements together • Used backtracking to explore subset possibilities • At each step, two choices exist: include the element or skip it • When skipping, moved forward past duplicate elements to avoid repeated subsets This ensures unique subsets are generated. 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • Sorting helps handle duplicates effectively • Backtracking explores all combinations systematically • Skipping duplicate elements prevents repeated subsets • Understanding recursion trees helps visualize subset generation 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(n × 2ⁿ) • Space: O(n) (recursion stack) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 When duplicates exist, generating combinations isn’t the challenge — avoiding repeated ones is. 33 days consistent 🚀 On to Day 34. #DSA #Arrays #Backtracking #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
Day 59 of My 90-Day Coding Challenge Today’s problem was a good reminder that clean thinking beats unnecessary setup. Initially, I approached it by creating a separate search space array (1–9) and building my solution on top of that. But then I stopped and questioned it: - Do I really need this extra structure? Turns out — I didn’t. I optimized the approach by directly using the index as the number, removing the need for any additional array. Key learning: • Not every problem needs extra data structures • Sometimes optimization is about removing what’s unnecessary • Cleaner recursion → better control over the solution #90DaysOfCode #DSA #Java #Recursion #Backtracking #ProblemSolving #LeetCode
To view or add a comment, sign in
-
-
🚀 Day 44/100 Today’s problem: Reverse Vowels of a String. 🔹 Problem Summary: Given a string, reverse only the vowels while keeping other characters in the same position. 🔹 Approach I Used: I applied the Two Pointer Technique: - One pointer from the start, one from the end - Move both until vowels are found - Swap them and continue 🔹 Key Learning: ✔ Two pointers can simplify string problems a lot ✔ Always break the problem into smaller steps ✔ Practice improves pattern recognition. 🔹 Example: Input: "IceCreAm" Output: "AceCreIm" 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(n) Consistency is the key 🔑 — showing up every day! #Day44 #CodingJourney #DSA #Java #Learning #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