⚡𝗗𝗮𝘆 𝟳𝟬 / 𝟭𝟮𝟬 𝗗𝗮𝘆𝘀 𝗼𝗳 𝗖𝗼𝗱𝗲 Before today’s update, a quick note -> I wasn’t posting regularly for a few days because I was actively working on building a project. Now back to sharing the learning again. 🚀 Problem -> Topological Sorting (DFS based) =>Topological sorting is used in Directed Acyclic Graphs (DAGs) to order vertices such that for every directed edge u → v, node u appears before v in the ordering. In simple terms -> it helps determine dependency order (like course scheduling or task execution order). Approach -> → Use Depth First Search (DFS) → Maintain a visited array to track visited nodes → Use a stack to store the order of nodes → Traverse all vertices of the graph → For every unvisited node, perform DFS → After exploring all neighbors of a node, push it into the stack → Finally, pop elements from the stack to get the topological order Key Insight -> A node is added to the stack only after all its dependencies are visited, ensuring correct ordering. Time Complexity -> O(V + E) Space Complexity -> O(V) This problem helped me understand how DFS can be used to solve dependency ordering problems in graphs. #120DaysOfCode #Day70 #Graphs #TopologicalSort #DFS #Java #DSA
Topological Sorting with DFS in Directed Acyclic Graphs
More Relevant Posts
-
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 #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
-
-
📌 Median of Two Sorted Arrays Platform: LeetCode #4 Difficulty: Hard ⚙️ Approach • Apply binary search on the smaller array for efficiency • Define search space from 0 to n1 • Partition both arrays such that: – Left half contains (n1 + n2 + 1) / 2 elements – Right half contains remaining elements • Identify boundary elements: – l1, l2 → left side elements – r1, r2 → right side elements • Check valid partition: – l1 <= r2 and l2 <= r1 • If valid: – For even length → median = average of max(left) and min(right) – For odd length → median = max(left) • If not valid: – If l1 > r2, move left – Else move right 🧠 Logic Used • Binary Search on partition index • Dividing arrays into balanced halves • Handling edge cases using boundary values • Achieving optimal O(log(min(n1, n2))) time complexity 🔗 GitHub: https://lnkd.in/g_3x55n8 ✅ Day 36 Completed – Revised advanced binary search and partition-based problem. #100DaysOfCode #Java #DSA #ProblemSolving #CodingJourney #Algorithms #DataStructures #LeetCode #CodingPractice #CodeEveryDay #BinarySearch #ArrayProblems
To view or add a comment, sign in
-
-
Day 67/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Subsets II Another classic backtracking problem with a twist (duplicates). Problem idea: Generate all possible subsets (power set), but avoid duplicate subsets. Key idea: Backtracking + sorting to handle duplicates. Why? • We need to explore all subset combinations • Duplicates in input can lead to duplicate subsets • Sorting helps us skip repeated elements efficiently How it works: • Sort the array first • At each step, add current subset to result • Iterate through elements • Skip duplicates using condition: 👉 if (i > start && nums[i] == nums[i-1]) continue • Choose → recurse → backtrack Time Complexity: O(2^n) Space Complexity: O(n) recursion depth Big takeaway: Handling duplicates in backtracking requires careful skipping logic, not extra data structures. This pattern appears in many problems (subsets, permutations, combinations). 🔥 Day 67 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #Backtracking #Recursion #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟓𝟖 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on finding two numbers in a sorted array that add up to a target. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Two Sum II – Input Array Is Sorted 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 • Used two pointers: • One at the beginning (left) • One at the end (right) • Calculated sum of both elements Logic: • If sum == target → return indices • If sum < target → move left pointer forward • If sum > target → move right pointer backward This works because the array is already sorted. 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • Sorting enables two-pointer optimization • Two pointers reduce time complexity from O(n²) to O(n) • Direction of movement depends on comparison with target • Index-based problems often become simpler with sorted data 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(n) • Space: O(1) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 When data is sorted, two pointers can turn a complex problem into a simple one. 58 days consistent 🚀 On to Day 59. #DSA #Arrays #TwoPointers #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
🔥🚀 DAY 37/60 – Minimum Height Trees! #geekstreak60 Challenge Powered by NPCI Day 37 completed ✅ Today’s problem was Finding Roots of Minimum Height Trees (MHT) 🌳 The idea is to find nodes that produce the minimum tree height when chosen as root. Approach used: Topological Trimming (BFS on Leaves) ✔ Built graph using adjacency list ✔ Calculated degree of each node ✔ Added all leaf nodes (degree = 1) to queue ✔ Repeatedly removed leaves layer by layer ✔ Remaining nodes (≤ 2) are the centers of the tree These centers are the roots of Minimum Height Trees. 💡 ⏱ Time Complexity: O(V + E) 💾 Space Complexity: O(V + E) Today’s takeaway: Sometimes instead of building the answer directly, we remove unnecessary parts layer by layer to reach the core. 🧠⚡ 37 Days strong. Graph patterns getting deeper every day 🔥 #geekstreak60 #DSA #Java #Graph #BFS #TopologicalSort #ProblemSolving #CodingJourney #Consistency 🚀
To view or add a comment, sign in
-
-
🚀 Solved: Vertical Order Traversal of a Binary Tree (Hard) Just wrapped up solving one of the trickier tree problems — and it was a great reminder that details matter in Data Structures & Algorithms. 🔍 Key Challenge: Not just grouping nodes by vertical columns, but also: Maintaining row-wise ordering Handling same row & same column cases Ensuring sorted output using a min-heap (PriorityQueue) 💡 Core Insight: Instead of a simple BFS, the correct approach required: 👉 Column → Row → MinHeap mapping This ensures: Columns are processed left → right Rows are processed top → bottom Values are sorted when positions overlap ⚙️ Tech Used: BFS traversal TreeMap (for sorted columns & rows) PriorityQueue (for value ordering) 📊 Result: ✔️ All test cases passed ⚡ Runtime: 4 ms 📉 Memory optimized 🧠 Big Learning: Sometimes a problem looks like a simple traversal… …but hidden constraints turn it into a multi-level sorting problem. #DSA #Java #LeetCode #BinaryTree #CodingInterview #ProblemSolving #SoftwareEngineering #LearningJourney
To view or add a comment, sign in
-
-
🧠 Day 199 — Number of Ways to Arrive at Destination 🛣️📊 Today I solved a powerful variation of Dijkstra’s Algorithm where we don’t just find the shortest path — we also count how many such shortest paths exist. 📌 Problem Goal Given a weighted graph: ✔️ Find the minimum time to reach destination ✔️ Count the number of distinct shortest paths ✔️ Return answer modulo 109+710^9 + 7109+7 🔹 Core Idea Use Dijkstra’s Algorithm, but with an extra array: 👉 ways[i] → number of shortest ways to reach node i 🔹 Approach 1️⃣ Build adjacency list with (node, time) 2️⃣ Maintain: • dist[] → shortest distance • ways[] → number of ways 3️⃣ Use min-heap (priority queue) 4️⃣ For each edge: • If shorter path found → update distance & reset ways • If equal path found → add ways 🔹 Key Insight ✔️ Shortest path + counting paths together ✔️ When distance improves → overwrite ways ✔️ When equal → accumulate ways 🧠 Key Learning ✔️ Dijkstra can be extended beyond just distance ✔️ Tracking multiple states (distance + count) is powerful ✔️ Modulo handling is important for large answers 💡 Today’s Realization Graph problems are reaching an advanced stage: • BFS → shortest path (unit weight) • Dijkstra → weighted shortest path • Dijkstra + DP → count paths Same algorithm → deeper layers. 🚀 Momentum Status: Advanced graph + DP integration getting strong. On to Day 200. #DSA #Graphs #Dijkstra #DynamicProgramming #LeetCode #Java #CodingJourney #ConsistencyWins
To view or add a comment, sign in
-
-
Day 50/100 | #100DaysOfDSA 🚀🔥 Today’s problem: Word Search Given a grid of characters and a word, we need to check if the word exists by moving horizontally or vertically. At first it feels like simple traversal… But the catch? You can’t reuse the same cell twice. Approach: • Try starting from every cell • Use DFS + Backtracking • Match characters step by step • Mark visited cells and backtrack if path fails Time Complexity: O(m × n × 4^L) Space Complexity: O(L) (recursion stack) Big takeaway: When choices branch in multiple directions, Backtracking is the key. Half century done. Staying consistent. 💯 Day 50 complete. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #Backtracking #DFS #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 52/100 🚀 | #100DaysOfDSA Solved LeetCode 69 – Sqrt(x) today. The task was to compute the integer square root of a number without using built-in functions like sqrt(). Approach: • Applied Binary Search on the range [0, x]. • Calculated mid and checked if mid * mid == x. • If mid * mid < x, stored mid as a possible answer and searched in the right half. • Otherwise, moved to the left half. • Used (long) while multiplying to avoid integer overflow. Time Complexity: O(log n) Space Complexity: O(1) Key takeaway: Binary Search is not limited to sorted arrays — it can be applied to search spaces defined by mathematical conditions. Steady progress, one problem at a time. 💪 #100DaysOfDSA #LeetCode #DSA #Java #BinarySearch #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