✅ Day 28 of 100 Days LeetCode Challenge Problem: 🔹 #133 – Clone Graph 🔗 https://lnkd.in/gsciP4qv Learning Journey: 🔹 Today’s problem focused on creating a deep copy of a connected graph. 🔹 I used Depth-First Search (DFS) to traverse the graph and clone each node. 🔹 A hashmap stores the mapping between original nodes and their cloned counterparts to avoid duplicate copies. 🔹 This approach also handles cycles gracefully by returning already-cloned nodes when revisited. Concepts Used: 🔹 Depth-First Search (DFS) 🔹 Graph Traversal 🔹 Hash Map 🔹 Deep Copy Key Insight: 🔹 Graph cloning requires tracking visited nodes to prevent infinite loops. 🔹 DFS provides a clean recursive way to clone nodes and their neighbors. 🔹 Maintaining a reference map is essential for handling cyclic graphs correctly. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
Clone Graph with DFS and Hash Map
More Relevant Posts
-
✅ Day 39 of 100 Days LeetCode Challenge Problem: 🔹 #114 – Flatten Binary Tree to Linked List 🔗 https://lnkd.in/g6xn2K3g Learning Journey: 🔹 Today’s problem focused on transforming a binary tree into a flattened linked list in-place. 🔹 I used an iterative approach, modifying pointers while traversing the tree. 🔹 For each node with a left subtree, I found the rightmost node of that subtree and connected it to the current node’s right subtree. 🔹 Then, I moved the left subtree to the right and continued traversal. Concepts Used: 🔹 Binary Trees 🔹 Tree Traversal 🔹 Pointer Manipulation 🔹 In-place Modification Key Insight: 🔹 Tree restructuring problems often rely on careful pointer adjustments. 🔹 Finding the predecessor (rightmost node of left subtree) helps preserve traversal order. 🔹 Iterative solutions can avoid recursion and reduce extra space usage. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
To view or add a comment, sign in
-
-
✅ Day 50 of 100 Days LeetCode Challenge Problem: 🔹 #696 – Count Binary Substrings 🔗 https://lnkd.in/gqvcumf3 Learning Journey: 🔹 Today’s problem focused on counting substrings where consecutive groups of 0s and 1s have equal length. 🔹 I analyzed transitions between groups of characters and counted valid balanced segments. 🔹 The idea was to track runs of consecutive characters and compare adjacent group lengths. 🔹 By accumulating the minimum of neighboring group sizes, I identified all valid binary substrings. Concepts Used: 🔹 String Traversal 🔹 Two-Pointer / Group Counting 🔹 Pattern Recognition 🔹 Greedy Counting Key Insight: 🔹 Binary substring problems often reduce to analyzing consecutive character groups. 🔹 Instead of checking all substrings, comparing adjacent group sizes gives an efficient solution. 🔹 Recognizing repeating patterns helps avoid brute-force complexity. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
To view or add a comment, sign in
-
-
✅ Day 34 of 100 Days LeetCode Challenge Problem: 🔹 #38 – Count and Say 🔗 https://lnkd.in/gZKE3maw Learning Journey: 🔹 Today’s problem focused on generating the nth term of the Count and Say sequence. 🔹 Each term is built by reading the previous term and describing consecutive digits using Run-Length Encoding (RLE). 🔹 I iteratively generated each sequence starting from "1" until reaching the desired term. 🔹 A helper function handles counting consecutive characters and forming the next sequence. Concepts Used: 🔹 String Manipulation 🔹 Run-Length Encoding (RLE) 🔹 Iterative Simulation 🔹 Pattern Recognition Key Insight: 🔹 Many sequence problems rely on recognizing and encoding patterns. 🔹 Breaking the logic into a helper function improves readability and correctness. 🔹 Iterative construction avoids unnecessary recursion and keeps the solution efficient. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
To view or add a comment, sign in
-
-
✅ Day 53 of 100 Days LeetCode Challenge Problem: 🔹 #191 – Number of 1 Bits 🔗 https://lnkd.in/gZPa-tQf Learning Journey: 🔹 Today’s problem focused on counting the number of set bits (1s) in the binary representation of an integer. 🔹 I converted the number to its binary form and iterated through the string representation. 🔹 By counting occurrences of '1', I determined the Hamming weight of the number. 🔹 This approach is simple and clear for understanding bit representation. Concepts Used: 🔹 Bit Manipulation 🔹 Binary Representation 🔹 String Conversion 🔹 Counting Technique Key Insight: 🔹 Every integer can be analyzed at the bit level for efficient computation. 🔹 Converting to binary provides an intuitive way to visualize set bits. 🔹 Bit manipulation problems often have multiple optimized approaches beyond basic counting. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
To view or add a comment, sign in
-
-
✅ Day 38 of 100 Days LeetCode Challenge Problem: 🔹 #323 – Number of Connected Components in an Undirected Graph 🔗 https://lnkd.in/gRVWsWgZ Learning Journey: 🔹 Today’s problem focused on counting connected components in an undirected graph. 🔹 I represented the graph using an adjacency list built from the edge list. 🔹 Using Depth-First Search (DFS), I explored all nodes reachable from a starting node. 🔹 Each new DFS traversal from an unvisited node indicates a new connected component. Concepts Used: 🔹 Depth-First Search (DFS) 🔹 Graph Representation (Adjacency List) 🔹 Connected Components 🔹 Graph Traversal Key Insight: 🔹 Graph problems often reduce to exploring connectivity between nodes. 🔹 Tracking visited nodes prevents redundant traversals. 🔹 Iterative DFS using a stack provides a clean and efficient solution. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
To view or add a comment, sign in
-
-
✅ Day 35 of 100 Days LeetCode Challenge Problem: 🔹 #62 – Unique Paths 🔗 https://lnkd.in/gx2ZcaVk Learning Journey: 🔹 Today’s problem focused on counting the number of unique paths in a grid from the top-left to the bottom-right corner. 🔹 Instead of using Dynamic Programming, I applied a mathematical combinatorics approach. 🔹 The problem reduces to choosing positions for moves (right and down) in a fixed sequence. 🔹 Using combinations provides a clean and optimal solution with constant space. Concepts Used: 🔹 Combinatorics 🔹 Mathematical Optimization 🔹 Problem Reduction 🔹 Grid Path Counting Key Insight: 🔹 Grid path problems often have a direct combinatorial interpretation. 🔹 Recognizing the fixed number of moves simplifies the problem significantly. 🔹 Mathematical solutions can be more elegant and efficient than DP in certain cases. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
To view or add a comment, sign in
-
-
✅ Day 40 of 100 Days LeetCode Challenge Problem: 🔹 #1200 – Minimum Absolute Difference 🔗 https://lnkd.in/gdXZxeGh Learning Journey: 🔹 Today’s problem focused on finding all pairs of elements with the minimum absolute difference in an array. 🔹 I first sorted the array so that the smallest differences would appear between adjacent elements. 🔹 By scanning the sorted list once, I tracked the minimum difference and collected all valid pairs. 🔹 This approach avoids unnecessary comparisons and improves efficiency. Concepts Used: 🔹 Sorting 🔹 Greedy Scanning 🔹 Array Traversal 🔹 Optimization Key Insight: 🔹 Sorting simplifies many comparison-based problems. 🔹 Minimum differences in a sorted array will always occur between neighboring elements. 🔹 Maintaining a running minimum helps build the result efficiently in one pass. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
To view or add a comment, sign in
-
-
📚 Today’s Learning: Stack – Data Structure & Algorithms Learned the fundamentals of Stack (LIFO – Last In, First Out) and how it works using operations like Insert, Delete, and Access. Understanding stacks helps in solving real problems like expression evaluation, undo/redo operations, and recursion handling. One step closer to mastering DSA 🚀 #DSA #Stack #LearningJourney #ComputerScience #ProblemSolving #Python
To view or add a comment, sign in
-
Day 15 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the factorial of a number using recursion. The goal was to understand how recursion works and how a function can call itself to solve a problem. What the program does: • Takes an integer input from the user • Uses recursion to calculate the factorial • Handles the base case properly • Returns the final factorial value How the logic works: The function factorial(n) is defined If n == 0, the function returns 1 (Base Case) Otherwise, the function returns: n * factorial(n - 1) The function keeps calling itself with smaller values The recursion stops when it reaches the base case The final result is printed Example: Input: 7 Output: 5040 (Because 7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5040) Key learnings from Day 15: – Understanding recursion and base cases – Learning how function calls are stacked – Breaking a problem into smaller subproblems – Strengthening fundamental algorithm concepts #100DaysOfCode #Day15 #Python #PythonProgramming #Recursion #Algorithms #ProblemSolving #CodingPractice #LearnByDoing #ComputerScience #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟱 | 𝟭𝟬𝟬 𝗗𝗮𝘆𝘀 𝗼𝗳 𝗟𝗲𝗲𝘁𝗖𝗼𝗱𝗲 𝗧𝗼𝗽𝗶𝗰: Backtracking & Recursion 𝗣𝗿𝗼𝗯𝗹𝗲𝗺𝘀 𝘀𝗼𝗹𝘃𝗲𝗱: 1) Subsets Key takeaway: This is the "Hello World" of backtracking. I focused on the Decision Tree logic: at every index, we have two choices—either include the number in our current set or exclude it. Managing the global state by "popping" after the recursive call (the actual backtracking step) is finally starting to feel like second nature. 2. Sum of All Subsets XOR Total Key takeaway: A perfect follow-up to the Subsets problem. It showed me how to apply a mathematical transformation (XOR) across the same recursive structure. Instead of just building a list, I learned how to aggregate a running total across all branches of the recursion. Backtracking is starting to click. It’s all about visualizing the tree and being disciplined with the state changes. Day 5 done. On to Day 6. #100DaysOfLeetCode #DSA #Backtracking #Recursion #Python #LeetCode #Consistency #LearningInPublic
To view or add a comment, sign in
-
Explore related topics
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