Most people think DSA is about memorizing algorithms. Today's problem proved it's not. It's about patterns. 🚀 Day 85/365 — DSA Challenge Solved: Longest Repeating Character Replacement At first, this problem looked confusing. You can change at most k characters. And you need the longest substring with same letters. Brute force? Too slow. Then the key idea clicked: We don't need to actually replace characters. We just need to know: How many characters in the current window are NOT the most frequent character. If that number is more than k, shrink the window. If it's <= k, expand the window. This becomes a Sliding Window problem. 💡 Core Idea window_size - max_frequency <= k If this condition is true → valid window If false → move left pointer ⏱ Complexity Time: O(n) Space: O(1) Day 85/365 complete. 💻 280 days to go. Code: https://lnkd.in/dad5sZfu #DSA #Java #LeetCode #SlidingWindow #Algorithms #LearningInPublic
Cracking DSA with Patterns: Longest Repeating Character Replacement
More Relevant Posts
-
#Day74 of my second #100DaysOfCode Binary search variations getting more interesting now. DSA • Solved Find Minimum in Rotated Sorted Array (LeetCode 153) – Brute: linear scan → O(n) – Optimal: binary search with an early check for already sorted part → O(log n) • Key idea: the minimum always lies in the unsorted portion, and if a part is already sorted, the answer can be taken directly • Difference from previous problems: instead of searching for a target, we’re tracking the minimum while narrowing the search space • Edge cases: – already sorted array – single element case – careful updates while narrowing the range This one was more about understanding the pattern than just applying binary search. #DSA #BinarySearch #LeetCode #Algorithms #Java #100DaysOfCode #WomenWhoCode #BuildInPublic #LearningInPublic
To view or add a comment, sign in
-
-
Day 36 of Daily DSA 🚀 Solved LeetCode 443: String Compression ✅ Problem: Given an array of characters, compress it in-place using run-length encoding. Each group of consecutive repeating characters is replaced by the character followed by its count (if count > 1). The result must be stored back in the input array. Rules: * If a group's length is 1 → append only the character * If a group's length is > 1 → append character + count * Group lengths ≥ 10 are split into multiple characters * Must use only constant extra space * Return the new length of the array Approach: Used a StringBuilder to build the compressed string by tracking consecutive character counts, then wrote the result back into the input array. Steps: 1. Append the first character to StringBuilder 2. Iterate through the array counting consecutive duplicates 3. On a new character → if count > 1, append the count 4. Append the new character and reset count 5. Handle the last group after the loop 6. Write compressed characters back into the input array ⏱ Complexity: • Time: O(n) • Space: O(n) (StringBuilder) 📊 LeetCode Stats: • Runtime: 3 ms (Beats 12.04%) • Memory: 45.58 MB (Beats 42.35%) A great exercise in in-place array manipulation and run-length encoding — fundamentals that show up everywhere in data compression. #DSA #LeetCode #Java #Strings #RunLengthEncoding #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🧠 Day 38 / 100 – DSA Practice Solved Word Search on LeetCode 🔍✅ 🔹 Problem: Given a 2D grid of characters and a word, check if the word exists in the grid by traversing adjacent cells (horizontally or vertically). 🔹 Approach: Used DFS + Backtracking: Start from each cell Explore all 4 directions (up, down, left, right) Mark visited cells to avoid reuse Backtrack if the path doesn’t match 🔍 Key Insight: Backtracking helps explore all possible paths while ensuring each cell is used only once per path 🔹 Complexity: ⏱ Time → O(m × n × 4^L) 📦 Space → O(L) recursion stack 💯 Result: ✔️ All test cases passed ⚡ Runtime: 130 ms (Beats 73%) Great problem to strengthen DFS & Backtracking concepts 🚀 #Day38 #100DaysOfCode #LeetCode #Java #DSA #Backtracking #DFS #Algorithms #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 30 of the DSA Grind: Translating Trees into Strings (and back again)! Today, I built a full two-way encoding engine from scratch for Serialize and Deserialize Binary Tree (LeetCode 297). This isn't just a traversal problem; it's an absolute masterclass in C++ memory management and string parsing. 🌳💻 Here is the breakdown: ⚙️ 1. The Serializer (Live Memory to String) I used a Level-Order (BFS) engine to flatten the tree. But there is a massive trap: you MUST explicitly record the null pointers (I used "#,"). If you skip them, the tree's physical shape is lost forever. The C++ Danger Zone: If you don't lock down your if/else blocks perfectly, your compiler will try to read the value of a NULL node and instantly hit you with a Segmentation Fault. Strict memory routing is required! ⚙️ 2. The Deserializer (String back to Live Memory) How do you turn a massive, flat string like "1,2,3,#,#,4,5," back into live TreeNode pointers? Enter the C++ stringstream. Instead of writing messy for loops to search for commas, I loaded the string into a stream. Using getline, it acted as an infinite dispenser, feeding exactly one node at a time into my BFS queue so I could perfectly wire up the left and right children. The Binary Tree architecture is officially locked in. The momentum is unreal right now! 🔥 #DSA #LeetCode #DataStructures #Algorithms #BinaryTrees #SoftwareEngineering #TechJourney #Coding #CPlusPlus #InterviewPrep
To view or add a comment, sign in
-
-
🚀 DSA Preparation 💪 Solved an advanced Binary Search problem on a rotated sorted array. Learned how to identify the sorted half and efficiently narrow down the search space 🔥 🧠 Problem 🔎 Search in Rotated Sorted Array Given a sorted array nums that is rotated at an unknown index, and a target value: 👉 Return the index of the target if found, otherwise return -1. 👉 The solution must run in O(log n) time complexity. Example Input: nums = [4,5,6,7,0,1,2], target = 0 Output: 4 Input: nums = [4,5,6,7,0,1,2], target = 3 Output: -1 Input: nums = [1], target = 0 Output: -1 ⚡ Key Learning 📌 Even after rotation, one half of the array is always sorted 📌 Use Binary Search to decide which half to explore 📌 Time Complexity: O(log n) → reduces search space by half in each step, making it highly efficient even for large inputs 📌 Space Complexity: O(1) Improving DSA with advanced searching techniques 🚀 #DSA #LeetCode #BinarySearch #Algorithms #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🔥 DSA Challenge – Day 130/360 🚀 📌 Topic: Backtracking / DFS on Grid 🧩 Problem: Word Search Problem Statement: Given a 2D grid of characters and a word, check if the word exists by moving in 4 directions (no cell reuse). 🔍 Example: Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]] word = "ABCCED" Output: true 💡 Approach: Backtracking + DFS 1️⃣ Step 1 – Start from every cell matching the first character 2️⃣ Step 2 – Explore 4 directions (up, down, left, right) recursively 3️⃣ Step 3 – Mark visited cells and backtrack after exploring ✔️ Avoid revisiting the same cell ✔️ Stop early when characters don’t match ✔️ Return true as soon as full word is found ⏱ Complexity: Time: O(N * M * 4^L) Space: O(L) (recursion stack) 📚 Key Learning: Backtracking is powerful for exploring all possible paths while avoiding invalid ones using pruning. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #130DaysOfCode #LeetCode #Backtracking
To view or add a comment, sign in
-
-
🚀 DSA Preparation 💪 Solved a fundamental Binary Search problem, a key concept for efficient searching. Focused on reducing search space by half in each step to achieve optimal performance 🔥 🧠 Problem 🔎 Binary Search Given a sorted array nums and a target value, return its index if found. If the target does not exist, return -1. 👉 The solution must run in O(log n) time complexity. Example Input: nums = [-1,0,3,5,9,12], target = 9 Output: 4 Input: nums = [-1,0,3,5,9,12], target = 2 Output: -1 ⚡ Key Learning 📌 Binary Search works only on sorted arrays 📌 Each step halves the search space → highly efficient 📌 Time Complexity: O(log n) 📌 Space Complexity: O(1) Improving DSA with strong fundamentals 🚀 #DSA #LeetCode #BinarySearch #Algorithms #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 30/160 of my DSA journey Today I solved the Search in a Rotated Sorted Array problem. Key Insight: Even after rotation, at least one half of the array is always sorted. Using this property, we can decide which side to search using Binary Search. Approach: • Found mid element using binary search • Checked which half is sorted (left or right) • If left half is sorted → checked if key lies in that range • Else → searched in right half • Repeated until element found or search space exhausted Concepts reinforced: • Binary Search on rotated arrays • Identifying sorted halves • Conditional search space elimination Time Complexity: O(log n) ⚡ Another step forward in problem solving 🚀 #Day30 #160DaysChallenge #DSA #GeeksforGeeks #LeetCode #CodingJourney #ProblemSolving #Algorithms #Java
To view or add a comment, sign in
-
-
Day 105: Circular Arrays & Shortest Paths 🔄 Problem 2515: Shortest Distance to Target String in a Circular Array Today’s challenge involved finding the minimum steps to reach a target string in a circular array, allowing movement in both directions. The Strategy: • Bidirectional Search: Since the array is circular, the distance can be calculated in two ways: moving forward or moving backward. • Modular Arithmetic: I used (dist + n) % n to handle the wrap-around logic seamlessly, ensuring the index stays within bounds regardless of the direction. • Optimization: By iterating once through the array and comparing the distances for every occurrence of the target, I maintained an O(N) time complexity. Sometimes the most elegant way to handle a "circular" problem is simply embracing the symmetry of the path. 🚀 #LeetCode #Java #Algorithms #ProblemSolving #DailyCode
To view or add a comment, sign in
-
-
The High Cost of the Wrong Initial Choice I have seen complex computation logic for over a million records take hours to run simply because of inefficient, row-by-row processing that is offered by database stored procedures and traditional java/python code. It is slow, impossible to scale, and eventually kills your product's edge in the market. By moving to vectorized logic with tools like NumPy or Polars, you can turn those hours of computation into milliseconds. This is not just about using newer tools, it is about leveraging modern execution like #SIMD (Single Instruction Multiple Data) and #multithreading to gain a massive competitive advantage. If your backend is computation heavy and you're still stuck in legacy loops, you are leaving performance, market edge and money on the table. References: https://lnkd.in/g8j3A5Bn https://lnkd.in/gaPnFUQm https://lnkd.in/gWt9WHnp #DataEngineering #SystemDesign #NumPy #PerformanceOptimization #Scalability #PythonProgramming #TechStrategy #Vectorization #TechToolChoice
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