🚀 Day 28 of my DSA Journey (LeetCode + Java) Today’s focus was completely on Sliding Window + Hashing patterns. All three problems looked different, but the core logic was about maintaining a valid window and updating the answer efficiently. ✅ Problems Solved Today: LC 3 – Longest Substring Without Repeating Characters LC 424 – Longest Repeating Character Replacement LC 1004 – Max Consecutive Ones III 🧠 My Experience Solving These: 🔸 3. Longest Substring Without Repeating Characters This is a classic sliding window + HashMap problem. Used a HashMap to store last index of characters If a character repeats, moved left pointer smartly Calculated window length using right - left + 1 Very clean logic once the window movement is clear. 🔸 424. Longest Repeating Character Replacement This one was tricky but powerful. Maintained frequency array for characters Tracked the most frequent character (maxCount) If window size – maxCount > k → shrink window Understanding why maxCount doesn’t decrease was the key insight. 🔸 1004. Max Consecutive Ones III Sliding window on array with condition. Count number of zeros in the window If zeros > k → move left pointer Always track maximum window length Simple idea, very effective solution. 📌 Key Takeaway Today: Sliding Window problems are all about maintaining a valid window. ✔ Decide what makes window invalid ✔ Expand using right pointer ✔ Shrink using left pointer ✔ Update answer at every step ✔ Avoid nested loops → O(n) always wins The more I practice, the faster I recognize patterns. 💪 Consistency + daily effort = confidence. On to Day 29 🚀 #DSA #LeetCode #Java #SlidingWindow #HashMap #ProblemSolving #CodingJourney #Consistency #LearningDaily
Day 28 of DSA Journey: Sliding Window & Hashing Patterns
More Relevant Posts
-
🚀 Day 1/30 – Java DSA Challenge 🔎 Problem 7: 2744. Find Maximum Number of String Pairs (LeetCode – Easy) Solved my seventh problem for Day 1 of the 30 Days DSA challenge. 🧠 Problem Statement We are given an array of distinct strings, where each string has length 2. We can form a pair (i, j) if: ✔ words[i] is equal to the reverse of words[j] ✔ 0 ≤ i < j < words.length ✔ Each string can belong to at most one pair We need to return the maximum number of pairs that can be formed. 💡 Example Input: ["cd","ac","dc","ca","zz"] Output: 2 Explanation: "cd" pairs with "dc" "ac" pairs with "ca" Maximum pairs = 2 👨💻 Approach ✔ Use nested loops to check all possible pairs ✔ For each pair, reverse one string ✔ If reversed string matches the other → increment count ✔ Return total count Since the constraints are small (≤ 50), a brute-force approach works efficiently.⏱ Time Complexity: O(n²) Because we compare every pair of strings. 📦 Space Complexity: O(1) No extra data structures used (only temporary strings). 📌 Key Learning: When constraints are small, a simple brute-force solution is often acceptable and easier to implement. Seven problems completed on Day 1 🔥💪 Building consistency one problem at a time 🚀 #Day1 #30DaysOfCode #Java #DSA #LeetCode #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 1/30 – Java DSA Challenge 🔎 Problem 2: 3110. Score of a String (LeetCode – Easy) Solved my second problem for Day 1 of the 30 Days DSA challenge. 🧠 Problem Statement The score of a string is defined as the sum of the absolute difference between ASCII values of adjacent characters. We need to return the total score. 💡 Example Input: "hello" ASCII values: h = 104 e = 101 l = 108 l = 108 o = 111 Score calculation: |104 − 101| + |101 − 108| + |108 − 108| + |108 − 111| = 3 + 7 + 0 + 3 = 13 👨💻 Approach ✔ Start from index 1 ✔ Compare each character with its previous character ✔ Add the absolute difference to a running sum Since characters in Java are stored using ASCII values internally, we can directly subtract them. ⏱ Time Complexity: O(n) – We traverse the string once. 📦 Space Complexity: O(1) – Only a single variable is used. 📌 Key Learning: Understanding how characters are stored internally (ASCII values) helps simplify string problems. Excited to continue this journey 🚀 #Day1 #30DaysOfCode #Java #DSA #LeetCode #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day25 - LeetCode Journey Solved LeetCode 344: Reverse String in Java ✅ This was a simple problem on the surface, but it perfectly highlights how powerful clean logic can be. The goal was to reverse a string in-place using O(1) extra space, which means no extra arrays and no shortcuts. Just pure two-pointer logic. Using the left and right pointers and swapping characters step by step felt very satisfying. It’s one of those patterns that looks small but appears everywhere in interviews and real-world problems. Mastering this makes many string and array problems much easier later on. What I liked about this problem is how it teaches efficiency. Instead of creating new memory, we directly modify the existing array. That mindset of optimizing space is extremely important in DSA. Key takeaways: • Strong practice of the two-pointer technique • In-place operations with constant extra space • Clean and readable swapping logic • Reinforced fundamentals of string manipulation ✅ Accepted successfully ✅ 0 ms runtime with optimal performance Sometimes the simplest problems build the strongest foundations. Consistency with basics is what makes complex problems feel easier later 💪 #LeetCode #DSA #Java #Strings #ProblemSolving #Algorithms #CodingJourney #InterviewPreparation #TwoPointers #Consistency #DailyPractice
To view or add a comment, sign in
-
-
🚀 Day 2/30 – Java DSA Challenge 🔎 Problem 12: 1299. Replace Elements with Greatest Element on Right Side (LeetCode – Easy) Solved another array traversal problem today 🔥 This problem focuses on understanding how to compare elements on the right side of an array. 🧠 Problem Statement Given an array arr, replace every element with the greatest element among the elements to its right. ✔ Replace the last element with -1 ✔ Return the modified array 💡 Example Input: [17,18,5,4,6,1] Output: [18,6,6,6,1,-1] Explanation: Each element is replaced by the maximum element present to its right. 👨💻 Approach (Brute Force) ✔ Traverse each index ✔ For every element, check all elements to its right ✔ Find the maximum among them ✔ Replace current element with that maximum ✔ For the last element → assign -1 Since constraints are manageable, this approach works. ⏱ Time Complexity: O(n²) – Nested loops 📦 Space Complexity: O(1) – In-place modification 📌 Key Learning: Understanding brute-force solutions is important before moving to optimized right-to-left traversal (which can reduce it to O(n)). Day 2 progressing consistently 💪🔥 Small steps every day lead to big improvements 🚀 #Day2 #30DaysOfCode #Java #DSA #LeetCode #ArrayProblems #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Started the Arrays & ArrayLists module today. Arrays were the first place where I felt the shift from writing Java syntax to actually solving problems. I began with Linear Search — simple, but important. int[] arr = {4, 7, 1, 9, 3}; int target = 9; boolean found = false; for (int i = 0; i < arr.length; i++) { if (arr[i] == target) { found = true; break; } } System.out.println(found); // Output : true What this made clear: - arrays force you to think in terms of indices - traversal is the base of almost every array problem - breaking early (break) matters for efficiency - even simple problems depend on clean loop logic This felt like the right starting point before moving into more complex array operations. Continuing with Arrays & ArrayLists today. #Java #DSA #Arrays #LearningInPublic #Programming #CodingJourney #ProblemSolving #ComputerScience #DeveloperJourney #JavaDeveloper
To view or add a comment, sign in
-
🚀 Day 3/30 – Java DSA Challenge 🔎 Problem 20: 205. Isomorphic Strings (LeetCode – Easy) Today’s problem focused on bidirectional mapping using HashMap 🔥 🧠 Problem Statement Two strings s and t are isomorphic if: ✔ Each character in s maps to exactly one character in t ✔ No two characters in s map to the same character in t ✔ Order must be preserved Example: "egg" → "add" ✅ "paper" → "title" ✅ "foo" → "bar" ❌ 💡 Approach Used To ensure correct mapping in both directions: ✔ Use two HashMaps map1 → s → t map2 → t → s ✔ Traverse both strings together ✔ Check consistency in both maps ✔ If conflict found → return false This ensures one-to-one mapping (bijection). ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) – At most 256 ASCII characters 📌 Key Learning Learned importance of two-way mapping Understood how to validate bijection Strengthened string + HashMap logic 20 Problems Completed 🔥 Day 3 progressing strong 💪🚀 #Day3 #30DaysOfCode #Java #DSA #LeetCode #HashMap #StringProblems #CodingJourney #Consistency
To view or add a comment, sign in
-
-
DSA journey 🚀 📌 LeetCode #268 – Missing Number 💻 Language: Java 🔹 Approach: Use the sum of first n natural numbers formula Calculate the expected sum: n * (n + 1) / 2 Find the actual sum of array elements The difference gives the missing number 🔹 Formula Used: Missing Number = Expected Sum − Actual Sum ⏱ Time Complexity: O(n) 🧩 Space Complexity: O(1) Simple math, clean logic ✨ Consistency over perfection 💯 #DSA #Java #LeetCode #ProblemSolving #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Week 2 of Java DSA – Arrays Deep Dive This week, I went deeper into Arrays using Java and focused on improving problem-solving skills through medium-level DSA problems. 🔹 What I worked on: • Arrays in depth (indexing, patterns, edge cases) • Optimizing solutions using better logic • Solving medium-level array problems • Improving time complexity awareness while coding 🔹 Key learnings: • Small optimizations can make a big difference • Handling edge cases is as important as core logic • Writing efficient array-based solutions requires clarity, not speed Continuing the journey with more challenging problems ahead 🚀 #Java #DSA #Arrays #ProblemSolving #LearningInPublic #Consistency #LeetCode
To view or add a comment, sign in
-
-
Today I worked on a fun little pattern-checking problem in Java: detecting a “trionic” array — one that goes: strictly increasing ➝ strictly decreasing ➝ strictly increasing What I like about this solution is that it’s clean, fast, and doesn’t overcomplicate things with extra arrays or nested loops. It simply walks the array once, identifying the turning points: p = peak of the first increasing run q = bottom after the decreasing run flag = end of the final increasing run And then validates that: ✅ all three phases exist ✅ each phase has at least one step ✅ the last phase reaches the end of the array Time complexity: O(n) Space complexity: O(1) Leetcode problem link:https://lnkd.in/g8nkhR85 #Java #DSA #Algorithms #CodingInterview #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Over the last 7 days, I focused on strengthening my core Java problem-solving skills. Instead of solving random problems, I followed a structured plan covering numbers, recursion, arrays, and strings. Here’s what I practiced: Day 1–2: Number logic and recursion * Reverse number * Palindrome number * Sum of digits * Fibonacci (iterative & recursive) * Factorial (iterative & recursive) * Armstrong number * Sum of digits until single digit Day 3: Prime and special numbers * Check prime number * Print prime numbers in a range * Strong number Day 4–5: Array fundamentals * Bubble sort * Maximum and second largest element * Reverse an array * Insert element at end and at position * Remove duplicates (two-pointer technique) * Left and right rotations * Left rotate by K Day 6–7: String problems * Reverse string * Palindrome string * Count vowels * Character frequency * Anagram check * First non-repeating character * Check unique characters * Reverse each word in a sentence Key learnings: * Improved logical thinking * Better understanding of time and space complexity * Clear difference between brute force and optimized solutions * Stronger foundation for technical interviews Instead of solving 200 random questions, I focused on mastering around 30 core problems deeply. #Java #CodingPractice #ProblemSolving #InterviewPreparation #SoftwareDeveloper
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