Continuing my 100 Days of DSA journey. Day 70 — LeetCode (Longest Repeating Character Replacement) 1) Longest Repeating Character Replacement – Given a string s and an integer k, return the length of the longest substring that can be obtained by replacing at most k characters so that all characters in the substring are the same. Approach (Sliding Window + Frequency Tracking): a) Use a sliding window with two pointers to maintain a valid substring b) Keep a frequency array to track count of characters in the current window c) Track the count of the most frequent character in the window d) If (window size - max frequency) > k, shrink the window from the left e) This ensures we replace at most k characters f) Update the maximum window length at each step Time Complexity: O(n) Space Complexity: O(1) On to Day 71... #100DaysOfCode #DSA #LeetCode #Cpp #CyclicSort #Algorithms #CodingJourney #ProblemSolving #SoftwareEngineering #InterviewPrep #LearningInPublic #geeksforgeeks #Microsoft #SlidingWindow #Strings #Optimization
LeetCode Longest Repeating Character Replacement Solution
More Relevant Posts
-
Continuing my 100 Days of DSA journey. Day 76 — LeetCode (Minimum Window Substring) - Hard Minimum Window Substring – Given two strings s and t, return the minimum window in s which will contain all the characters in t. If there is no such window, return an empty string. Approach (Sliding Window + Hashing): a) Use two hash maps to track required characters and current window frequency b) Maintain two pointers to represent the window (left and right) c) Expand the window by moving the right pointer and update frequency d) Keep track of how many required characters are satisfied e) When all characters are matched, try to shrink the window from the left f) Update the minimum window length whenever a valid window is found g) Continue the process until the entire string is traversed Time Complexity: O(n) Space Complexity: O(1) Key takeaway: Learned how combining sliding window with frequency tracking helps efficiently solve complex substring problems with multiple constraints. On to Day 77... #100DaysOfCode #DSA #LeetCode #Cpp #CyclicSort #Algorithms #CodingJourney #ProblemSolving #SoftwareEngineering #InterviewPrep #LearningInPublic #geeksforgeeks #Microsoft #SlidingWindow #Hashing #Strings #TwoPointers
To view or add a comment, sign in
-
-
Continuing my 100 Days of DSA journey. Day 71 — LeetCode (Valid Parentheses) Valid Parentheses – Given a string containing just '(', ')', '{', '}', '[' and ']', determine if the input string is valid. A string is valid if open brackets are closed by the same type and in the correct order. Approach (Stack): a) Use a stack to keep track of opening brackets b) Traverse the string character by character c) If an opening bracket is encountered, push it onto the stack d) If a closing bracket is found: Check if the stack is empty → if yes, return false Otherwise, compare with the top of the stack If it matches the corresponding opening bracket, pop it Else, return false e) At the end, if the stack is empty → valid, otherwise invalid Time Complexity: O(n) Space Complexity: O(n) Key takeaway: Learned how stack helps in handling nested and ordered structures efficiently, especially in problems involving matching pairs. On to Day 72... #100DaysOfCode #DSA #LeetCode #Cpp #CyclicSort #Algorithms #CodingJourney #ProblemSolving #SoftwareEngineering #InterviewPrep #LearningInPublic #geeksforgeeks #Microsoft #Stack #Strings #Parentheses #DataStructures
To view or add a comment, sign in
-
-
#Day54 of DSA Journey | LeetCode Challenge https://lnkd.in/d-K_WYsS Problem: Maximum Path Score in a Grid (Medium) Today’s problem combined Dynamic Programming + Grid Traversal + Constraints — a solid brain workout Understanding the Problem: We have a grid with values {0, 1, 2}: 0 → score +0, cost 0 1 → score +1, cost 1 2 → score +2, cost 1 Goal: Move from (0,0) → (m-1,n-1) (only right or down) Maximize score while keeping total cost ≤ k Key Insight: This is not a simple path problem — it’s a bounded optimization problem. We must track: Position (i, j) Cost used so far So state becomes: dp[i][j][cost] = max score Approach (DP): Use 3D DP Initialize start cell Traverse grid For each move (right/down): Update cost & score Only proceed if cost ≤ k
To view or add a comment, sign in
-
-
Day 91 on LeetCode —Final Prices With a Special Discount 🛒💸✅ Today’s problem focused on array traversal and discount simulation logic. not apply stack because my array logic works equally fine 🔹 Approach Used in My Solution • Traverse each item in the prices array • Search on the right side for the first smaller or equal value • Apply that value as a discount • Store updated answers directly in the result array Simple, clean, and easy to understand. ⚡ Complexity: • Time Complexity: O(n²) • Space Complexity: O(n) 💡 Key Takeaways: • Sometimes a direct array traversal approach explains the logic more clearly • Focused on building the solution step-by-step instead of forcing optimization immediately • Even brute force approaches strengthen understanding of problem flow and conditions 🔥 Consistency and clarity in logic matter just as much as optimization. #LeetCode #DSA #Algorithms #DataStructures #Arrays #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #Consistency #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
DSA day 228 ✅ ❓ Check if There is a Valid Path in a Grid The goal is to determine if there exists a valid path from top-left to bottom-right. 💡 Approach: Modeled the grid as a graph Used DFS (Depth First Search) Maintained a direction map for valid movements Ensured bidirectional connectivity (important trick!) Used a visited matrix to avoid cycles ⚡ Complexity: Time: O(N × M) Space: O(N × M) (visited + recursion stack) #CheckifThereisaValidPathinGrid #DSA #LeetCode #Graphs #Coding #ProblemSolving #CPlusPlus
To view or add a comment, sign in
-
-
DSA 40/45 🚀 I’ve been diving deep into Data Structures, and today was all about the "logic behind the library." While C++ STL makes life easy, manually implementing Stacks and Queues using dynamic arrays was a game-changer for my understanding of memory management. Key takeaways from today: > LIFO vs. FIFO: It’s one thing to use .push(), it’s another to manage the topIndex manually. > Circular Queues: Using the modulo operator (i + 1) % size to prevent "false overflow" and reuse memory efficiently. It's essentially turning a linear array into a never-ending circle. > Memory Safety: Why destructors and delete[] are non-negotiable when dealing with pointers. > Almost at the finish line of this 45-day journey. The more I learn, the more I realize that the best code isn't just about what works—it's about how it works under the hood. #DSA #Cpp #CodingChallenge #SoftwareEngineering #DataStructures #BuildingInPublic #Programming #Cpp #TechCommunity
To view or add a comment, sign in
-
-
Continuing my 100 Days of DSA journey. Day 69 — LeetCode (Balanced Binary Tree) Balanced Binary Tree – Given a binary tree, determine if it is height-balanced (i.e., the heights of left and right subtrees of every node differ by no more than 1). Approach (DFS + Height Optimization): a) Use a recursive function to calculate the height of each subtree b) For each node, recursively get the height of left and right subtrees c) If any subtree returns -1, propagate -1 upwards (indicating imbalance) d) Check if the absolute difference between left and right heights is greater than 1 e) If unbalanced, return -1 immediately f) Otherwise, return 1 + max(leftHeight, rightHeight) Time Complexity: O(n) Space Complexity: O(h) (recursion stack) On to Day 70... #100DaysOfCode #DSA #LeetCode #Cpp #Algorithms #CodingJourney #ProblemSolving #SoftwareEngineering #InterviewPrep #LearningInPublic #geeksforgeeks #Microsoft #Greedy #Strings #Optimization
To view or add a comment, sign in
-
-
🚀 Leveling up my DSA skills: Mastering the Sliding Window! I recently tackled the "Longest Substring Without Repeating Characters" problem on LeetCode using C++. This was a great exercise in optimizing time complexity and understanding how to manage dynamic windows within a string. 💡 The Approach To solve this efficiently, I used the Sliding Window technique combined with an unordered_map: Expansion: The high pointer expands the window by adding characters to the frequency map. Contraction: If the number of unique characters in the map is less than the window size ($f.size() < k$), it means we have a duplicate. The low pointer then slides forward, removing characters until the window is valid again. Efficiency: This approach ensures we traverse the string in $O(n)$ time, which is much better than a brute-force $O(n^2)$ search. #LeetCode #CodingJourney #CPP #DataStructures #Algorithms #SoftwareEngineering #ProblemSolving #SlidingWindow #Programming
To view or add a comment, sign in
-
-
💡 DSA Day 216 ✅ ❓ Shortest Distance to Target String in a Circular Array 🔍 The Challenge: In a circular array of size n, distance isn’t always straight. You have to consider both directions: Direct distance: |i - start| Wrap-around distance: n - |i - start| ✨ The Insight: Take the minimum of both: min(direct, wrap-around) This keeps the solution clean and efficient: ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) #Coding #DataStructures #CPP #LeetCode #ProblemSolving #ShortestDistancetoTargetStringinaCircularArray
To view or add a comment, sign in
-
-
I'm happy to share this, hope it helps someone. During my time in the automotive industry, I built a real-time quality control tool using computer vision, designed to detect wire harness components directly on the production line. The app worked great, but completely tied to proprietary data, so it stayed private. I've now cleaned it up, stripped all company specific elements, swapped the custom model for a publicly available YOLOv8 one, and restructured the codebase into a proper modular template that anyone can use. What it does: - Runs real-time object detection from a webcam or image file. - Displays detected objects with class labels and confidence scores. - Exports results as a text report or PDF label. Seneca once wrote in his Letters to Lucilius: “If wisdom were given me under the express condition that it must be kept hidden and not uttered, I should refuse it.” I’m no Seneca, but I think this may be useful for someone; feel free to use it, fork it, or build on it. For more details, check the README on GitHub: https://lnkd.in/dMdKb4Xe #Python #ComputerVision #YOLO #OpenSource #MachineLearning
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