Today I worked on a classic string problem: Finding the length of the longest substring that contains no repeated characters. 🧠 What the problem asks: Given a string, identify the longest continuous sequence where all characters are unique, and return its length. 📌 Key Observations: A substring must be continuous (not scattered like a subsequence) As soon as a character repeats, the current window becomes invalid The goal is to maintain a window of unique characters only 🔍 How I approached it: I used the Sliding Window technique with two pointers. This helped me: Expand the window when characters are unique Shrink it when duplicates appear Track the maximum length efficiently This approach avoids rechecking characters repeatedly and keeps the solution optimal. ✔ Example Insights: "abcabcbb" → longest substring: "abc" → length 3 "bbbbb" → "b" → length 1 "pwwkew" → "wke" → length 3 💡 Takeaway: This problem reinforces how powerful sliding window techniques are for real-world string and array challenges. Great practice for improving logic, efficiency, and pattern recognition. #LeetCode #CodingPractice #Python #Algorithms #100DaysOfCode #SlidingWindow #ProblemSolving #TechJourney
Solved the longest substring without repeated characters problem using Sliding Window technique.
More Relevant Posts
-
Day 16 of #100DaysOfLeetCode Today’s problem focused on substring counting within binary strings and required an efficient approach to handle potentially large input sizes without generating every substring explicitly. 1. Number of Substrings With Only 1s The task was to count the total number of substrings that consist entirely of the character '1', with the final result taken modulo (10^9 + 7). Instead of constructing the substrings, the key insight is that each continuous block of 1s contributes a predictable number of valid substrings. 🔹 My Approach: Iterated through the string while tracking the current streak length of consecutive 1s. Each time a block ended, computed the number of substrings from that block using the formula: k*(k+1)/2 where k is the length of the streak. Added the total from each block to the final answer, applying the modulo constraint throughout. Completed the process with a final update for any trailing block of 1s. What I Learned: This problem reinforces how recognizing mathematical patterns within sequences can transform a brute-force solution into a simple linear scan. Efficient substring counting often comes down to understanding structure rather than enumerating possibilities. 📊 Complexity Analysis: Time Complexity: O(n) — single pass over the string. Space Complexity: O(1) — constant space approach. #day16 #100daysofleetcode #leetcode #DSA #python #leetcodes #striver
To view or add a comment, sign in
-
-
DAY-1:CODING CHALLENGE 1.Longest common Prefix substring from given string as input 2.3SUM problem Started with BRUTE-FORCE → checked every triplet. 😀 Worked 😇 but SLOW for big arrays (O(n³)) → TIME LIMIT EXCEEDED. Faced errors along the way: 'int object not iterable' → I wrote sorted(a,b,c) instead of sorted([a,b,c]). 'unhashable type: list' → Tried adding list to set. Fixed by converting to tuple. LOGICAL BUG → Return inside the loop returned early. Fixed by moving return outside. Finally moved to OPTIMAL TWO-POINTER APPROACH: Sort array first. Use two pointers to find pairs for target -nums[i]. Skip duplicates carefully. Complexity reduced to O(n²). 💡 Lessons learned: small syntax mistakes can cause big errors, immutable types are key for sets, and proper pointer logic makes code efficient. #Python #Algorithms #LeetCode #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
✅ LeetCode 3446 – Sort Matrix by Diagonals Successfully solved another interesting matrix manipulation problem! 🧩 Problem Summary: Given an n × n matrix, the task is to sort: The bottom-left diagonals (including the main diagonal) in non-increasing order. The top-right diagonals in non-decreasing order. 💡 Approach: Use a dictionary to group elements by diagonal index (j - i). Sort each diagonal individually based on its position (top or bottom triangle). Reconstruct the matrix by placing back the sorted values. ⚙️ Key Concepts: Matrix traversal Diagonal indexing (j - i) Sorting and reconstruction 📊 Result: ✅ Accepted with 0 ms runtime 💪 Optimized, clean, and easy-to-read solution #LeetCode #Python #ProblemSolving #CodingChallenge #DataStructures #Algorithms #Matrix #DeveloperJourney
To view or add a comment, sign in
-
-
Today I solved LeetCode 3321 - Find X-Sum of All K-Long Subarrays II (Hard) #day14 of #1001DaysOfCode The challenge is to compute the “x-sum” for every subarray of length k. Instead of simply summing values, we first: Count occurrences of each number in the subarray Select the top x most frequent elements (breaking ties by choosing the larger value) Then sum only those selected elements with all their occurrences A direct recalculation for every sliding window would be too slow, so the key idea was to maintain frequency counts incrementally and keep the top-x elements efficiently balanced using two heaps. To solve it, I used: A sliding window to move across the array efficiently A frequency map to track counts Two heaps (in for top-x elements, out for remaining elements) A dynamic rebalancing step to ensure correctness as counts change Detailed explanation + code here: https://lnkd.in/dD4e5WNh #LeetCode #Python #DataStructures #Heaps #Algorithms #CodingChallenge #SoftwareEngineering #CompetitiveProgramming
To view or add a comment, sign in
-
-
Day 5 of #100DaysOfLeetCode Problem: 54. Spiral Matrix Category: Arrays / Matrix Traversal Today’s challenge focused on traversing a 2D matrix in spiral order and returning all elements in that pattern. This problem was really fun to solve because it required handling multiple edge cases while maintaining clean traversal logic. 🧠 Key Learnings: Used the concept of repeatedly peeling off the outer layer of the matrix. Traversed top row → right column → bottom row → left column in sequence. Understood the importance of checking matrix boundaries after each step to avoid index errors. Improved logical thinking for problems involving nested data structures. 🎯 Takeaway: Matrix traversal problems are all about maintaining control over direction and boundaries — once that’s handled, the logic flows smoothly. #LeetCode #100DaysOfCode #ProblemSolving #CodingJourney #Matrix #Arrays #Python #AIEngineer #Consistency
To view or add a comment, sign in
-
-
🚀 Day 32 DSA Challenge – Problem #14: Longest Common Prefix Finding unity in diversity — even among strings 😄✨ 🎯 Problem Statement: Given an array of strings, return the longest common prefix shared among them. If there’s no common prefix, return an empty string "". 🧠 How I Solved It: Started by assuming the first string as the initial prefix. Iterated through each subsequent string, trimming the prefix until it matched the start of the current word. Used Python’s startswith() to efficiently check prefix matches. Stopped early if the prefix became empty — ensuring optimal performance. ⚙️ Performance Stats: ⏱ Runtime: 0ms (beats 100%) 💾 Memory: 12.52MB (beats 27.15%) ✅ Testcases Passed: 126 / 126 💡 What I Learned: This problem reinforced the value of incremental reduction and early termination in string algorithms. Sometimes, solving efficiently means knowing when to stop ⏳💬 #LeetCode #Problem14 #LongestCommonPrefix #StringManipulation #Python #AlgorithmDesign #100DaysOfCode #DSA
To view or add a comment, sign in
-
-
Day 11 of #100DaysOfLeetCode Problem: 14. Longest Common Prefix Category: Strings / Comparison / Iteration Today’s challenge focused on finding the longest common prefix among an array of strings. It’s a great problem that improves your understanding of string traversal, comparison, and boundary conditions. 🧠 Key Learnings: Iterated character by character through the first string and compared it with all other strings. Carefully handled edge cases where strings had different lengths or no common prefix. Reinforced the concept of early termination when a mismatch is found — improving efficiency. Strengthened skills in iterative string comparison and control flow logic. 🎯 Takeaway: Small details like string length and early exit conditions make a big difference in optimizing even the simplest problems. #LeetCode #100DaysOfCode #ProblemSolving #CodingJourney #Strings #Python #AIEngineer #Consistency
To view or add a comment, sign in
-
-
🚀 Day 3 of #100DaysofDSA Today’s focus was on the “Set Matrix Zeroes” problem — a classic array-matrix question that tests both logic and optimization thinking It began with the brute-force idea: storing all zero positions and then marking corresponding rows and columns later. It works but takes O(m × n) time and O(m + n) extra space. Next, then explored a better approach using two auxiliary arrays to track which rows and columns should be zeroed. This improved the clarity but still consumed additional memory and space. Finally, then to reduce the complexity I tackled the optimal solution, which achieves O(1) extra space by using the first row and first column of the matrix itself as markers. A small Boolean flag handles the edge case when the first row contains a zero. This subtle observation transforms the logic completely — turning a memory-heavy method into a clean in-place algorithm. It was a good reminder that optimization isn’t just about speed — it’s about finding elegance in constraints. #100DaysOfDSA #MatrixProblems #Optimization #SpaceComplexity #Python #ProblemSolving
To view or add a comment, sign in
-
-
✅ Learned to solve “Remove Duplicates from Sorted Array” (in-place, O(n) time, O(1) space)! Sorted input means every duplicate sits next to its twin—perfect setup for the two-pointer pattern: scan once, write uniques forward, and return the count k while keeping the first k positions clean and ordered. What clicked: - Two pointers: one scans, one writes uniques forward - Skip repeats deterministically thanks to sorting - Edge cases covered: empty array, all duplicates, negatives, mixed ranges Level-ups next: “Remove Duplicates II” (allow at most twice) and “Remove Element” to deepen the pattern muscle. What’s your favorite twist on this technique? 🚀 #LeetCode #TwoPointers #Arrays #InPlace #DSA #Algorithms #InterviewPrep #ProblemSolving #TimeComplexity #CodingChallenge #Python #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 68: Search in 2D Sorted Matrix (Search Space Reduction) 🔎 I'm continuing the streak on Day 68 of #100DaysOfCode with a challenging matrix search problem! The task is to find a target value in an $m \times n$ matrix where both rows and columns are sorted in ascending order. The key to solving this efficiently is Search Space Reduction. Instead of performing a standard search, my solution uses a smart traversal technique: Starting Point: I begin the search at the top-right corner of the matrix. Decision Logic: If the current value equals the target, we stop. If the current value is greater than the target, the entire current column can be eliminated, so we move left. If the current value is less than the target, the entire current row can be eliminated, so we move down. This strategy eliminates one row or one column in every step, guaranteeing an optimal O(m + n) time complexity and O(1) extra space. #Python #DSA #Algorithms #Matrix #Search #100DaysOfCode #ProblemSolving
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