🚀 Just solved LeetCode 30 – Substring With Concatenation of All Words. 🧩 What was the problem? Given a string and a list of words (all same length), you have to find every starting index where all the words appear together as a continuous substring, in any order. Basically a sliding-window puzzle with fixed word sizes and frequency matching. 🛠️ What was my approach? • Counted all words using a map • Used multiple sliding windows based on word length • Expanded the window word by word • If a word appeared more than needed, I moved the left pointer forward • Added the index when the window matched every word exactly The key was treating the string in equal chunks, not character by character. 📚 What I learned Working with strings becomes much easier when you break the problem into predictable pieces. Managing window boundaries is the real challenge here, and walking through tiny examples helps more than you think. #LeetCode #Java #DSA #CodingPractice #ProblemSolving
Solved LeetCode 30 – Substring With Concatenation of All Words
More Relevant Posts
-
🚀 Day 73 of #100DaysOfCode Today I solved LeetCode 3346 – Maximum Frequency of an Element After Performing Operations I 🧩 This problem was all about logical range manipulation — figuring out how many elements could be converted into the same number when each element can be modified by ±k, but with a limited number of allowed operations. At first, it felt similar to the “most frequent element” sliding window problem, but the twist here was controlling how many elements can be changed, not just the total cost. After a few failed attempts (and a battle with edge cases 😅), I finally implemented a correct solution using the difference array + prefix sum approach. 💡 Key Takeaways: Think in terms of ranges, not just differences. Prefix-sum (difference map) logic is incredibly powerful for interval counting. Always recheck constraints — “number of operations” vs “total cost” makes a huge difference! Here’s a snippet from my final Java solution: int achievable = Math.min(running, same + numOperations); ans = Math.max(ans, achievable); It’s small details like these that make problem-solving such a rewarding process 💪 #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #DSA #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Just solved LeetCode 648 – Replace Words. 🟩 What was the problem? You’re given a list of root words and a sentence. For every word in the sentence, you need to replace it with the shortest root that matches its prefix. If multiple roots match, you pick the smallest one. If none match, you leave the word as it is. 🛠️ What was my approach? • Grouped all roots in a HashMap based on their first character • Split the sentence into individual words • For each word, checked only the relevant roots (same starting character) • Picked the shortest matching root if multiple matched • Built the final updated sentence using a StringBuilder This avoided checking every root against every word and kept things pretty efficient. 📚 What I learned Working with strings becomes simpler when you organize the data around predictable patterns. Grouping roots by their first letter saved a lot of unnecessary comparisons. Small structural changes make the whole solution cleaner. #LeetCode #Java #DSA #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
-
✨ Day 57 of 100: Rotate List ✨ Today’s challenge was LeetCode 61 – Rotate List 🔄 Problem: Given the head of a linked list, rotate the list to the right by k places. Example: Input: head = [1,2,3,4,5], k = 2 Output: [4,5,1,2,3] Key Idea: To rotate the list: 1️⃣ Find the length of the linked list. 2️⃣ Connect the tail to the head to make it circular. 3️⃣ Calculate the new head position as length - (k % length) steps from the start. 4️⃣ Break the circle at the right point to get the rotated list. 💡 Key Takeaways: Strengthened understanding of linked list traversal and manipulation. Learned to handle edge cases like k larger than the list length efficiently using modulo. Practiced converting a circular list back into a normal one at the right node. 💬 Every day of this challenge reinforces how small logical tweaks — like using % to handle rotations — can make code elegant and efficient. #100DaysOfCode #LeetCode #Java #LinkedList #CodingChallenge #DSA #ProblemSolving #WomenWhoCode
To view or add a comment, sign in
-
-
💻 LeetCode 50 Days Challenge — Day 2: Longest Common Prefix Day 2 of my #LeetCode50DaysChallenge ✅ Today’s problem was all about string manipulation — Longest Common Prefix ✨ 🧩 Problem: Given an array of strings, find the longest common prefix among them. If there’s no common prefix, return an empty string "". 💡 Approach: I sorted the array alphabetically, then compared the first and last strings (since they’ll have the maximum difference). By comparing characters until they differ, I was able to build the common prefix using a StringBuilder. This approach is both elegant and efficient for the problem! ⏱️ Time Complexity: O(n × m) — where n is the number of strings and m is the length of the shortest string. 📊 Example: Input: ["flower", "flow", "flight"] Output: "fl" This problem really highlights how a simple sorting trick can simplify logic significantly. Feeling more confident with string problems — consistency is the key! 🔥 #LeetCode #CodingChallenge #Day2 #ProblemSolving #Java #SoftwareDevelopment #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 60 of My LeetCode Challenge Problem: Defanging an IP Address — LeetCode #1108 Today’s problem was a straightforward yet insightful string manipulation task. The goal was to replace every . in an IP address with [.]. 💡 Approach: Used a StringBuilder to efficiently construct the modified string: • Traversed each character in the given address. • When encountering a ., appended [.] to the builder. • For all other characters, appended them directly. • Converted the StringBuilder to a string and returned the result. This method ensures both clarity and efficiency while avoiding unnecessary string object creation. ⏱️ Time Complexity: O(n) — Single traversal of the string. 💾 Space Complexity: O(n) — New string built proportional to input length. Each day adds a small step toward mastering clean code and algorithmic thinking 💪 #LeetCode #Day60 #LeetCode1108 #Java #CodingChallenge #ProblemSolving #StringManipulation
To view or add a comment, sign in
-
-
🔹 Day 39 – LeetCode Practice Problem: Perfect Number (LeetCode #507) 📌 Problem Statement: A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding itself. Return true if the given number is perfect, otherwise return false. ✅ My Approach (Java): Initialize sum = 0. Iterate from 1 to num / 2. For every divisor i such that num % i == 0, add it to sum. After the loop, if sum == num, it’s a perfect number. 📊 Complexity: Time Complexity: O(n/2) Space Complexity: O(1) ⚡ Submission Results: Accepted ✅ Runtime: 2108 ms Memory: 41.19 MB 💡 Reflection: This problem reinforced the importance of divisor-based iteration. While this brute-force solution works, optimizing divisor checks using square roots can greatly improve performance — a good next step for refinement! #LeetCode #ProblemSolving #Java #DSA #CodingPractice #Learning
To view or add a comment, sign in
-
-
🚀 Day 391 of #500DaysOfCode Today, I solved LeetCode Problem 2011: Final Value of Variable After Performing Operations 🧮 📝 Problem Summary: You start with a variable X = 0 and a list of operations such as "++X", "X++", "--X", or "X--". Each "++" increases the value by 1, and each "--" decreases it by 1. The goal is to return the final value of X after performing all operations. 💡 Approach: Initialize X = 0. Loop through the list of operations. If the operation contains "++", increment X. Otherwise, decrement X. Return the final result. ✅ Example: Input: ["--X","X++","X++"] Output: 1 A simple yet elegant problem that helps sharpen conditional logic and string manipulation fundamentals. ⚡ #LeetCode #CodingChallenge #Java #100DaysOfCode #500DaysOfCode #ProblemSolving #LearnEveryday
To view or add a comment, sign in
-
-
💡 LeetCode 3467 – Transform Array 💡 Today, I solved LeetCode Problem #3467: Transform Array, which focuses on array manipulation and the use of conditional logic in Java — a neat problem that strengthens core programming fundamentals. ⚙️ 🧩 Problem Overview: You’re given an integer array nums. Your task is to: Replace even numbers with 0 Replace odd numbers with 1 Then, sort the transformed array in ascending order. 👉 Example: Input → nums = [4, 7, 2, 9] Output → [0, 0, 1, 1] 💡 Approach: 1️⃣ Iterate through the array. 2️⃣ Use a ternary operator to transform each element (even → 0, odd → 1). 3️⃣ Sort the array to arrange all zeros before ones. ⚙️ Complexity Analysis: ✅ Time Complexity: O(n log n) — due to sorting. ✅ Space Complexity: O(1) — in-place transformation. ✨ Key Takeaways: Practiced logical thinking and ternary operations in Java. Strengthened understanding of array transformations and sorting. Reinforced the value of writing clean, concise, and efficient code. 🌱 Reflection: Even simple transformation problems like this one sharpen the habit of thinking algorithmically. Consistency in small challenges leads to big growth in problem-solving skills. 🚀 #LeetCode #3467 #Java #ArrayManipulation #LogicBuilding #ProblemSolving #CodingJourney #DSA #CleanCode #ConsistencyIsKey
To view or add a comment, sign in
-
-
✨ Day 54 of 100: Reverse Nodes in k-Group ✨ Today’s challenge was LeetCode 25 – Reverse Nodes in k-Group 🔁 🧩 Problem: Given a linked list, reverse the nodes of the list k at a time and return its modified list. If the number of nodes is not a multiple of k, the remaining nodes should remain as-is. 💡 Key Takeaways: 🔹 Strengthened understanding of linked list manipulation and pointer handling. 🔹 Practiced breaking the list into segments of size k and reversing each group independently. 🔹 Learned how to manage head and tail connections between reversed and remaining parts. 🔹 Reinforced problem-solving using dummy nodes to simplify list operations. 🧠 Approach: 1️⃣ Count the total nodes to know how many full groups of k exist. 2️⃣ For each group, reverse k nodes iteratively. 3️⃣ Connect the reversed group to the next segment. 🧭 Insight: This problem beautifully illustrates how iteration with precise pointer movement can replace recursion while still achieving elegant reversals in linked lists. #100DaysOfCode #Day53 #LeetCode #Java #LinkedList #CodingJourney #DSA #ProblemSolving
To view or add a comment, sign in
-
-
🌟 Day 56 of My #LeetCode Challenge – Word Pattern (#290) Today’s problem focused on validating if a string follows a specific character pattern — a great exercise in understanding mapping relationships and string manipulation. The task was to ensure that: 1️⃣ Each character in the pattern maps to exactly one word in the string. 2️⃣ No two characters map to the same word — maintaining a perfect one-to-one (bijection) relationship. To solve this, I used a HashMap<Character, String> to store the mappings between each character and its corresponding word. If a character already exists, I checked whether it points to the same word. If not, I returned false immediately. I also used containsValue() to make sure no word was reused for a different character. This problem reinforced the importance of careful logic flow, map lookups, and validation in both directions to avoid conflicts in mapping. 💡 Key learning: Building bijections with HashMaps is a common pattern in many string and mapping problems, and mastering it really improves problem-solving skills. #LeetCode #Day56 #Java #CodingChallenge #ProblemSolving #100DaysOfCode #DataStructures #HashMap #LearningEveryday
To view or add a comment, sign in
-
More from this author
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
Excellent bro