🚀 Day 100 of #100DaysOfLeetCode Problem: 127. Word Ladder Difficulty: Hard Key Insight: This is a shortest-path problem where each valid word transformation is an unweighted edge — BFS guarantees the minimum sequence length. Approach: Used BFS starting from beginWord. At each step, generated all possible words by changing one character (a–z). Used a HashSet for O(1) lookup and removed visited words to avoid revisits. Complexity: Time: O(N × L × 26) Space: O(N) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
Word Ladder Problem Solution with BFS Approach
More Relevant Posts
-
#day333 of #1001daysofcode problem statement (0257): Binary Tree Paths 💡 Approach: Used DFS recursion to explore all root-to-leaf paths in the binary tree. While traversing, I kept building the path string. When a leaf node is reached, the complete path is added to the result list. Example path format: 1->2->5 ⏱ Time Complexity: O(n) 🧠 Space Complexity: O(h) — recursion stack (h = height of the tree) Consistency in solving one problem every day 📈 #1001DaysOfCode #DSA #Java #LeetCode #ProblemSolving Shivam Mahajan #leetcode
To view or add a comment, sign in
-
-
Day 42 of DSA 🚀 | Alternating Binary String Today’s problem: Minimum Changes To Make Alternating Binary String 🔹 Task: Convert a binary string into an alternating string (0101... or 1010...) using the minimum number of flips. 💡 Key Insight: Only two valid patterns exist: 010101... 101010... Count mismatches with one pattern and compute the other using: min(count, n - count) 📌 Example s = "0100" → Output = 1 ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) Small problem, but a great reminder that recognizing patterns can simplify the solution drastically. #DSA #Java #LeetCode #ProblemSolving #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day 98 of #100DaysOfCode Solved LeetCode #1356 – Sort Integers by The Number of 1 Bits ✅ A clean bit manipulation + sorting problem that rewards thinking beyond plain comparisons. Key Takeaways: -> Using Integer.bitCount() to count set bits efficiently -> Encoding sort priority directly into values for simplicity -> Leveraging built-in sorting for clean and fast solutions -> Small tricks can lead to elegant code ✨ Language: Java -> Runtime: 6 ms (Beats 93.70%) ⚡ -> Memory: 47.42 MB Almost there. Staying consistent till the end 💻🔥 #LeetCode #Java #BitManipulation #Sorting #ProblemSolving #DSA #100DaysOfCode
To view or add a comment, sign in
-
-
Day 7/100 – LeetCode Challenge Problem: Palindrome Number Today’s problem focused on number manipulation without converting the integer into a string. Approach: If number is negative → return false Reverse the digits using modulo (% 10) and division (/ 10) Compare reversed number with original number Logic Used: Extract last digit: rem = x % 10 Build reversed number: rev = rev * 10 + rem Remove last digit: x = x / 10 Complexity: Time: O(log₁₀ n) Space: O(1) Key takeaway: Problems involving digits can often be solved mathematically without string conversion. #100DaysOfCode #LeetCode #DSA #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
#Day58 of my second #100DaysOfCode Today’s problem was about carefully handling overlapping intervals. DSA • Solved Merge Intervals (LeetCode 56) • Implemented a brute force approach by checking and merging overlapping intervals → O(2n) + O(n log n) time • Implemented the optimal approach by sorting intervals and merging them in a single traversal → O(n log n) + O(n) time • Key idea: once intervals are sorted by start time, overlapping ranges can be merged efficiently in one pass These interval problems really test attention to detail with edge cases. #DSA #Algorithms #LeetCode #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
-
Day 10 of Daily DSA 🚀 Solved LeetCode 190: Reverse Bits ✅ 🔍 Approach: Worked with the 32-bit representation of the given integer: • Converted the number into a fixed 32-bit binary string • Used a two-pointer technique to reverse the bits • Converted the reversed binary back to an unsigned integer This approach keeps the logic simple while ensuring correctness for signed integers. ⏱ Complexity: • Time: O(32) = O(1) (constant time) • Space: O(32) = O(1) 📊 LeetCode Stats: • Runtime: 9 ms • Memory: 43.46 MB A good reminder that clarity matters more than micro-optimizations when learning bit manipulation. #DSA #LeetCode #Java #BitManipulation #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 32 of DSA 🚀 | Check If a String Contains All Binary Codes of Size K Today’s problem looked straightforward but tested how well I understand constraints and coverage. 🔹 Task: Check whether a binary string contains every possible binary code of length k as a substring. 🔹 Key realization: This is not about generating binary codes. It’s about verifying coverage using a sliding window. 💡 What I learned: Total binary codes of size k = 2^k Sliding window helps examine substrings efficiently HashSet tracks unique patterns automatically Correct boundary (s.length() - k) avoids runtime errors ⏱ Time Complexity: O(n × k) 📦 Space Complexity: O(2^k) 📌 Example: "00110110", k = 2 → all patterns {00, 01, 10, 11} exist → ✅ true This problem reinforced how small details in problem statements can completely change the approach. #DSA #SlidingWindow #Strings #Java #ProblemSolving #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
Day 16/30 – Sort Colors 🚀 Solved: Sort an array of 0s, 1s, and 2s in-place. Technique Used: Dutch National Flag Algorithm 🇳🇱 Pointers: • low → boundary for 0 • mid → current element • high → boundary for 2 Single pass. Constant space. Pure pointer manipulation. Time Complexity: O(n) Space Complexity: O(1) This problem is a masterclass in two-pointer control. #30DaysOfCode #Java #DSA #TwoPointers #InterviewPrep
To view or add a comment, sign in
-
-
Day 37 of DSA – Linked List Cycle Today I solved Linked List Cycle using the Two Pointer technique (Floyd’s Algorithm). Instead of using extra space (like a HashSet), I learned how to: Use a slow pointer (moves 1 step) Use a fast pointer (moves 2 steps) Detect a cycle when both pointers meet 💡 Key Insight: If there is no cycle → fast pointer reaches null. If there is a cycle → fast eventually catches slow. Time Complexity: O(n) Space Complexity: O(1) This problem strengthened my understanding of pointer movement and loop detection in linked lists. #100DaysOfCode #DSA #Java #LinkedList #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 73/100 of my DSA Journey ✅ Problem solved today: LeetCode 1461 – Check If a String Contains All Binary Codes of Size K 🧠 What I focused on: Using a HashSet to store all substrings of length k Sliding window technique to generate substrings efficiently Understanding why we only need to check if the number of unique substrings equals 2^k Handling edge cases when string length is smaller than k This problem nicely combined strings + sliding window + hashing logic. 📌 Key takeaway: Sometimes the solution is just counting unique patterns efficiently. 📈 Day 73 done. Consistency continues. #LeetCode #DSA #SlidingWindow #Strings #Hashing #Java #ProblemSolving #Consistency #LearningInPublic #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