Today I finally understood the logic behind the Longest Substring Without Repeating Characters problem from LeetCode — and honestly, the journey of understanding it was more valuable than just getting the answer. At first, the idea of Sliding Window felt confusing. I couldn’t visualize how the substring keeps changing and how the algorithm still finds the correct result. So instead of jumping straight to the code, I broke it down step by step like a beginner: Example string: pwwkew I started tracking a window of characters: [p] [p,w] duplicate w → remove from front [w] [w,k] [w,k,e] duplicate w → remove until duplicate gone [k,e,w] The key insight that finally clicked for me: The window keeps changing, but a separate variable keeps track of the best result. currentLength = end - start + 1 maxLength = Math.max(maxLength, currentLength) So even though the window moves, the algorithm never loses the best answer it has seen so far. This problem helped me understand two important concepts: • Sliding Window technique • Maintaining a running best value (maxLength) Sometimes the real learning happens when you slow down and understand the logic instead of just memorizing the solution. Still learning, still exploring. 🚀 #DSA #Java #ProblemSolving #CodingJourney #SlidingWindow
Understanding Longest Substring Without Repeating Characters on LeetCode
More Relevant Posts
-
🚀 Solved “Search Insert Position” using Binary Search on LeetCode! Today I worked on an interesting problem where the goal is to find the index of a target element in a sorted array. If the target is not present, we return the index where it should be inserted to maintain sorted order. 🔍 Approach: Instead of using a linear search (O(n)), I implemented an efficient Binary Search (O(log n)) approach. 💡 Key Learning: One important detail is calculating the middle index safely: mid = low + (high - low) / 2 This avoids potential integer overflow compared to (low + high) / 2 and ensures correct behavior even for large inputs. ⚙️ Logic: If target == arr[mid] → return mid If target > arr[mid] → search right half Else → search left half If not found → return ‘low’ as the correct insert position 📈 Result: Achieved 100% performance on LeetCode 🚀 This problem reinforced my understanding of: ✔ Binary Search fundamentals ✔ Edge case handling ✔ Writing optimized and safe code Looking forward to solving more problems and improving problem-solving skills! #LeetCode #BinarySearch #Java #DataStructures #Coding #ProblemSolving
To view or add a comment, sign in
-
-
Day 80 of DSA Problem Solving Solved LeetCode 876 — Middle of the Linked List 🔥 Today’s problem was all about linked list traversal and using the two-pointer technique efficiently. 🚀 Problem Idea We are given the head of a singly linked list, and the task is to return the middle node of the linked list. If there are two middle nodes, we return the second middle node. 💡 Key Learning The main insight was: If we use two pointers, one moving 1 step at a time and the other moving 2 steps at a time, then by the time the fast pointer reaches the end of the list, the slow pointer will be standing at the middle node. So instead of counting the total number of nodes first, we can directly find the middle in just one traversal. 🧠 Concepts Practiced Two Pointer Technique Linked List Traversal Fast and Slow Pointer Single Pass Traversal Pointer Movement Logic ⏱ Time Complexity Time: O(n) Space: O(1) 📈 Real Journey Behind the Solution At first, this problem looks very basic, and the brute force idea of counting nodes and then reaching the middle can come to mind quickly. But this question teaches a much smarter and cleaner approach using slow and fast pointers. This problem helped me strengthen my understanding of linked list fundamentals and pointer movement, which are extremely important in coding interviews. Every day, I’m realizing that even easy problems can teach very powerful concepts when solved with the right approach. #Day80 #DSA #LeetCode #Java #LinkedList #TwoPointers #CodingJourney #ProblemSolving #CodingDaily
To view or add a comment, sign in
-
-
Day 29: The Anatomy of a Bug — Three Types of Errors 🐞 In programming, not all "crashes" are created equal. We categorize errors into three levels of severity, ranging from "The computer doesn't understand you" to "The computer does exactly what you said, but you said the wrong thing." 1. Syntax Errors (The "Grammar" Mistake) These happen before the code even starts running. Python’s "Parser" looks at your script and realizes it violates the rules of the language. The Cause: Missing colons :, unclosed parentheses (, or incorrect indentation. The Result: The program won't start at all. 💡 The Engineering Lens: These are the "cheapest" errors to fix. Your code editor (IDE) will usually highlight these with a red squiggly line as you type. 2. Runtime Errors (The "Panic" Mistake) The syntax is perfect, and the program starts running—but then it hits a situation it can't handle. The Cause: Dividing by zero, trying to open a file that doesn't exist, or calling a variable that hasn't been defined yet (NameError). The Result: The program "crashes" in the middle of execution. 💡 The Engineering Lens: We handle these using Exception Handling (try/except). Professional code assumes things will go wrong (like the internet cutting out) and builds "safety nets" to keep the program alive. 3. Semantic Errors (The "Logic" Mistake) These are the most dangerous and difficult to find. The program runs perfectly from start to finish. There are no crashes and no red text. But the output is wrong. The Cause: You used + when you meant -, or your loop stops one item too early. The Result: The program gives you the wrong answer (e.g., a calculator saying $2 + 2 = 22$). 💡 The Engineering Lens: The computer is doing exactly what you told it to do; the "error" is in your logic. We find these using Unit Testing and Debugging tools. If you don't test your code, you might not even know a semantic error exists until a customer reports it. #Python #SoftwareEngineering #Debugging #ProgrammingTips #LearnToCode #TechCommunity #PythonDev #CleanCode #BugHunting
To view or add a comment, sign in
-
Day 4 — Pattern-Based DSA Practice Continuing to learn and build in public while solving problems pattern by pattern. Today's focus: Binary Search on Rotated Arrays & Peaks Problems solved: • Count Occurrences — Coding Ninjas • Minimum Element in Rotated Sorted Array — LeetCode • Number of Times Array is Rotated — CodeChef • Find Peak Element — LeetCode Key learning: Binary Search is not always applied on perfectly sorted arrays. It can also be extended to rotated arrays and peak-based problems by carefully analyzing conditions. Instead of searching for a target, many problems are about identifying the correct region where the answer lies. Slowly understanding how the same pattern adapts to different scenarios with slight logical changes. #DSA #BinarySearch #ProblemSolving #LearningInPublic #Java #CodingJourney
To view or add a comment, sign in
-
🚀 Day 84 – DSA Journey | Maximum Depth of Binary Tree Continuing my daily DSA practice, today I focused on understanding tree depth and recursive problem solving. 📌 Problem Practiced: Maximum Depth of Binary Tree (LeetCode 104) 🔍 Problem Idea: Find the maximum depth (or height) of a binary tree — the number of nodes along the longest path from the root to a leaf node. 💡 Key Insight: The depth of a tree depends on its subtrees. At every node, we can recursively calculate the depth of left and right subtrees and take the maximum. 📌 Approach Used: • If the node is null → depth is 0 • Recursively calculate depth of left subtree • Recursively calculate depth of right subtree • Return 1 + max(left, right) 📌 Concepts Strengthened: • Binary tree traversal • Recursion • Divide and conquer approach • Tree height calculation ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(h) (recursion stack) 🔥 Today’s takeaway: Breaking problems into smaller subproblems using recursion makes complex tree problems much easier to handle. On to Day 85! 🚀 #Day84 #DSAJourney #LeetCode #BinaryTree #Recursion #Java #ProblemSolving #Coding #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day 30/60 — LeetCode Discipline Problem Solved: 3Sum Closest Difficulty: Medium Today’s problem pushed beyond exact answers and focused on finding the closest possible sum to a given target — a subtle yet powerful variation of the classic 3Sum problem. By sorting the array and using a two-pointer approach, the solution efficiently explores combinations while continuously updating the closest result. This problem highlights how small modifications in logic can significantly change the nature of a problem — from exact matching to optimal approximation. 💡 Focus Areas: • Strengthened two-pointer technique • Practiced working with sorted arrays • Improved handling of optimization conditions • Learned to track and update closest values dynamically • Reinforced problem-solving under constraints ⚡ Performance Highlight: Achieved efficient runtime with optimized traversal. Not every problem asks for perfection — sometimes, the goal is to get as close as possible. #LeetCode #60DaysOfCode #100DaysOfCode #DSA #TwoPointers #Algorithms #ProblemSolving #CodingJourney #SoftwareEngineering #Java #Developers #Consistency #TechGrowth #LearnToCode
To view or add a comment, sign in
-
-
Day 55 of 100 Days of LeetCode 💻 Today I solved Longest Consecutive Sequence — and honestly, this one taught me more about coding discipline than algorithms. At first, my approach was correct: Used HashSet for O(1) lookup Applied the “start of sequence” logic But I still got TLE. The reason? A tiny mistake: if(!set.contains(num-1)); That single ; made my condition useless and turned my O(n) solution into O(n²). 💡 Lesson learned: Don’t just think your logic is right → verify what your code actually does Small syntax mistakes can completely break optimal solutions Debugging is just as important as problem-solving Finally fixed it and got Accepted ✅ Slowly improving not just in DSA, but in writing cleaner and more careful code. #100DaysOfLeetCode #DSA #Java #CodingJourney #Learning
To view or add a comment, sign in
-
-
🚀 Day 45 of #100DaysOfCode 🧩 Problem Solved: Longest Common Prefix Today’s challenge was to find the common prefix among a list of strings. I used an efficient approach by leveraging sorting. 💡 Approach: Sort the array of strings Compare the first and last strings Build the prefix character by character 🧠 Why this works: After sorting, the first and last strings are the most different. Their common prefix will be the answer for all strings. ⚡ Key Learning: Smart thinking > brute force. Using sorting can reduce unnecessary comparisons and simplify logic. 🏷️ Tags: #100DaysOfCode #Day45 #LeetCode #Java #DSA #CodingJourney #ProblemSolving #Algorithms #String #Array 📈 Staying consistent and improving step by step! 🚀
To view or add a comment, sign in
-
-
🚀 DAY 90/150 — Kth SMALLEST IN BST! 🌳🎯 Day 90 of my 150 Days DSA Challenge in Java and today I solved a very important Binary Search Tree problem that strengthens understanding of inorder traversal and optimization 💻🧠 📌 Problem Solved: Kth Smallest Element in a BST 📌 LeetCode: #230 📌 Difficulty: Medium 🔹 Problem Insight The task is to find the kth smallest element in a Binary Search Tree. 👉 Key Observation: Inorder traversal of BST gives sorted order So, the kth smallest element is simply the kth element in inorder traversal. 🔹 Approaches Used ✅ Approach 1: Store Inorder Traversal • Perform inorder traversal • Store elements in an ArrayList • Return the (k-1)th index ✔️ Simple but uses extra space ✅ Approach 2: Optimized Inorder (Better) • Traverse inorder without storing all elements • Keep a counter (index) • When index == k, store result ✔️ More efficient (no extra space needed) ⏱ Complexity Time Complexity: O(n) Space Complexity: • Approach 1 → O(n) • Approach 2 → O(h) 🧠 What I Learned • Inorder traversal is extremely useful in BST problems • We don’t always need extra space — optimization matters • Tracking state (like index) inside recursion is powerful 💡 Key Takeaway This problem taught me: Difference between brute force vs optimized approach How to reduce space complexity Writing clean recursive solutions 🌱 Learning Insight Now I’m focusing more on: 👉 Writing optimized solutions instead of just correct ones 🚀 ✅ Day 90 completed 🚀 60 days to go 🔗 Java Solution on GitHub: 👉 https://lnkd.in/gmaYG5s7 💡 Optimization is what separates good code from great code. #DSAChallenge #Java #LeetCode #BinarySearchTree #BST #InorderTraversal #Recursion #150DaysOfCode #ProblemSolving #CodingJourney #InterviewPrep #LearningInPublic
To view or add a comment, sign in
-
-
Two Pointers pattern — done. Here's what the last few days actually taught me. 🧵 Three Sum is Two Sum with a loop around it. First time I saw Three Sum — find all triplets that sum to zero — I thought it was a completely different problem. Turns out it isn't. Fix one element i. Now you just need two numbers from the rest of the array that sum to -arr[i]. That's Two Sum. Which is Two Pointers. Which you already know. Three Sum = loop + Two Sum. Four Sum = loop + Three Sum. The pattern scales. The core never changes. --- Dutch National Flag — the hardest-looking problem with the simplest explanation. Sort an array of only 0s, 1s, and 2s. In-place. No sort(). Single pass. The instructor explained it as a teacher sorting students — toppers (0) to the front, failures (2) to the back, average (1) stays in the middle. Three pointers: low, mid, high. Mid scans the unsorted zone and decides where each element belongs. O(n) time. O(1) space. One pass. The analogy made the algorithm stick instantly. --- The real output of this pattern: a decision framework. After every question, the same signals kept showing up: → Array or linked list problem → Sorted, or sorting helps → Merge / rearrange / remove duplicates in-place → Find a pair, triplet, or quadruplet Match two or more of these → Two Pointers is almost certainly the answer. Not intuition. A repeatable framework. Next: Sliding Window. Which, turns out, is just a specific type of Two Pointers. 💻 #DSA #TwoPointers #LeetCode #Java #CodingJourney #DSAPatterns #PadhoWithPratyush Pratyush Narain
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