Day: 21/365 Problem: Minimum Cost Path with Edge Reversals Medium Key takeaways / learnings: 1. Graph problems can often be transformed by redefining edge weights to model constraints like reversals or penalties. 2. Dijkstra works even when the graph is transformed, as long as all edge weights are non-negative. 3. Thinking in terms of cost instead of steps helps solve non-standard shortest path problems. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #Consistency 🥷
Transforming Graph Problems with Edge Reversals in Dijkstra's Algorithm
More Relevant Posts
-
#day306 of #1001daysofcode problem statement (0110): Balanced Binary Tree Solved “Balance a Binary Search Tree” today. Approach: 1. Perform inorder traversal to extract sorted values. 2. Rebuild the BST by picking the middle element recursively. Clean two-step transformation: flatten → rebuild. #1001DaysOfCode #DSA #Java #LeetCode #ProblemSolving Shivam Mahajan #leetcode
To view or add a comment, sign in
-
-
Optimizing Sorting Logic Using Bit Manipulation (Java) Today I solved a problem that required sorting integers based on the number of set bits in their binary representation. Instead of using a direct sorting approach, I implemented a custom comparator with a PriorityQueue and used Brian Kernighan’s algorithm to count set bits efficiently: n = n & (n - 1) This reduces time complexity for counting bits to O(number of set bits). 📊 Result: • 77/77 test cases passed • Runtime: 7ms • Beat 78% of submissions Key takeaway: Optimization is not just about solving — it’s about choosing the right approach and reducing unnecessary operations. Bit manipulation continues to be one of the most powerful tools in algorithm design. #DSA #Java #BitManipulation #LeetCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 29/100 – LeetCode Challenge 🚀 Problem: Same Tree Approach: Used recursive traversal Compared corresponding nodes of both trees Checked: both nodes null → identical one null → not identical values mismatch → not identical recursively compared left and right subtrees Time Complexity: O(n) Space Complexity: O(h) Key takeaway: Many tree comparison problems reduce to simultaneous traversal of both trees. #LeetCode #100DaysOfCode #DSA #Java #BinaryTree #ProblemSolving
To view or add a comment, sign in
-
-
Day 3 of Daily DSA 🚀 Solved LeetCode 1: Two Sum Approach: Used a HashMap to store numbers with their indices. For each element, checked if the complement (target - current) already exists. Complexity: • Time: O(n) • Space: O(n) Performance: Runtime: 2 ms (Beats 99.15%) Memory: 47.34 MB Focusing on writing clean and efficient solutions before over-optimizing. Consistency > Intensity 💯 #DSA #LeetCode #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day: 40/365 📌 LeetCode POTD: Add Binary Easy Key takeaways/Learnings from this problem: 1. This one’s a reminder that binary addition is just normal addition with a carry you manage manually, nothing fancy. 2. Big takeaway: when strings represent numbers, think digit-by-digit from the end — clean logic > converting to integers. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
-
Day 8 – Maximum Product of Two Elements Solved a problem that requires finding the maximum product from two array elements. Key Learnings: Tracking the largest and second-largest values in one pass Avoiding extra operations like sorting when not required Writing clear conditional logic #Java #Arrays #ProblemSolving #DSA
To view or add a comment, sign in
-
-
🚀 Day 6 of #100DaysOfDSA (Java) Today I worked on Pattern Problems ⭐ Focused on: Nested loops Row & column logic Understanding how output structure maps to loop structure At first, patterns feel confusing. But once you understand how rows and columns interact, everything becomes structured. Big takeaway today 👇 Patterns improve logical thinking and control over loops — which is the foundation for solving complex problems later. Small practice. Strong foundation. Day 6 ✅ Consistency is building discipline. #DSA #Java #CodingJourney #100DaysOfCode #ProblemSolving #FutureDeveloper #LearningInPublic
To view or add a comment, sign in
-
-
Day: 44/365 📌 LeetCode POTD: Count Binary Substrings Easy Key takeaways/Learnings from this problem: 1. The real trick is noticing you don’t need to check every substring — just track lengths of consecutive 0s and 1s. 2. Big takeaway: many string problems become simple once you focus on grouping patterns instead of brute force counting. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
-
🔥Day 91 of #100DaysOfLeetCode Problem: 1653. Minimum Deletions to Make String Balanced Difficulty: Medium Key Insight: A balanced string must have all 'a's before all 'b's. Any 'b' before an 'a' creates a violation. Approach: Preprocess the string using: - prefixB[i]: number of 'b's strictly before index i - suffixA[i]: number of 'a's strictly after index i For every index i, treat it as a split point and compute: deletions = prefixB[i] + suffixA[i] The minimum over all splits is the answer. Time Complexity: O(n) Space Complexity: O(n) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
Day: 23/365 Problem: Minimum Cost to Convert String I Medium Key takeaways/Learnings from this problem: 1. Floyd–Warshall is clutch when you need all-pairs minimum cost, especially with character-to-character conversions. 2. Precomputing the cheapest path once saves you from doing repeated work for every character in the string. 3.This problem is a good reminder that classic graph algos + small constraints = clean and elegant solution. #POTD #365DaysOfCode #DSA #Java #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