✂️ DSA Practice — Remove All Occurrences of a Character (Recursive Approach) Today I solved Remove all occurrences of a character in a string using a recursive approach, focusing on careful index handling and in-place modification. 🔍 Key Learnings Recursion is useful even for string manipulation problems. When modifying a string in-place, index management is critical. After deletion, characters shift left — so the index should not advance. Clear base cases prevent infinite recursion. 🧠 Why This Problem Matters Strengthens understanding of recursion with mutable data structures. Helps build intuition for string traversal and modification. Common problem to test attention to detail and edge cases. 📌 Final Takeaway This problem highlights that recursion isn’t just about breaking problems down — it’s also about understanding how data changes during execution. #dsa #recursion #strings #problemSolving #codingpractice #java #datastructures #interviewpreparation #algorithms #100DaysOfCode #softwareengineering
Recursive String Manipulation: Removing Characters
More Relevant Posts
-
🚀 DSA Journey | Day 4 — Majority Element (LeetCode) Today, I solved the Majority Element problem and focused on improving my approach from a brute force solution to an optimized one. 🔹 🧠 Problem Understanding Given an integer array, the task is to find the element that appears more than ⌊n/2⌋ times. ✔ The problem guarantees that a majority element always exists ✔ Focus is on optimizing the approach efficiently 🔹 ⚙️ Approach 1: Brute Force For each element, I traversed the entire array again to count its frequency If the frequency exceeded n/2, I returned that element ❌ Time Complexity: O(n²) 👉 Works fine but not scalable for large inputs 🔹 ⚡ Approach 2: Optimized (Using HashMap) Stored frequency of elements using a HashMap Identified the element with count greater than n/2 ✔ Time Complexity: O(n) ✔ Space Complexity: O(n) 💡 Significant improvement compared to brute force 🔹 💡 Key Learnings ✔ How to optimize from O(n²) → O(n) ✔ Importance of choosing the right data structure ✔ Better understanding of frequency-based problems #DSA #LeetCode #Java #ProblemSolving #CodingJourney #Day4 #Learning #Algorithms
To view or add a comment, sign in
-
-
🚀 DSA Journey Day 8 — LeetCode :Finding Duplicates in an Array Today’s problem looked simple at first… but the approach made all the difference 👀 🔍 Problem Understanding Given an integer array nums, return all elements that appear exactly twice. ⚡ Brute Force Approach For every element, traverse the entire array Count occurrences Time Complexity: O(n²) ❌ (Not efficient) 🚀 Optimized Approach (Using HashMap) Used a HashMap to store frequency of each element First pass → store counts Second pass → collect elements with frequency = 2 👉 Steps: Traverse the array Store frequency using map.getOrDefault() Iterate over the map If value == 2 → add to result list 🧠 Example Walkthrough Input: [4,3,2,7,8,2,3,1] Map: {1=1, 2=2, 3=2, 4=1, 7=1, 8=1} Output: [2,3] ⏱️ Complexity Analysis Time: O(n) ✅ Space: O(n) 💡 Key Learning Sometimes the problem isn’t hard… choosing the right data structure is what makes it efficient 🔥 ✅ Result ✔️ Accepted (29/29 test cases) ⚡ Runtime: 30 ms 🙏 Staying consistent and improving every day 📌 Consistency beats motivation #DSA #Java #CodingJourney #LeetCode #ProblemSolving #HashMap #100DaysOfCode #PlacementPreparation
To view or add a comment, sign in
-
-
DSA Challenge – Day 21 🚀 Continuing my Data Structures & Algorithms journey, today I solved the problem “Check if Binary String Has at Most One Segment of Ones.” 🔎 Problem Summary: Given a binary string s without leading zeros, determine whether it contains at most one contiguous segment of '1's. 💡 Approach: The key observation is that if multiple segments of '1' exist, the string will contain the pattern "01". So, by checking whether the string contains "01", we can easily determine if there is more than one segment of '1'. If "01" is present → multiple segments → return false If "01" is absent → only one segment → return true ⚡ Time Complexity: O(n) 📦 Space Complexity: O(1) 📈 Key Takeaway: Sometimes the most efficient solutions come from identifying simple patterns within the data rather than overcomplicating the logic. Looking forward to solving more problems and strengthening my problem-solving skills every day. #DSA #ProblemSolving #Java #CodingChallenge #SoftwareDevelopment #LearningInPublic
To view or add a comment, sign in
-
-
Day 53 of My DSA Journey Today I solved a problem on searching an element in a rotated sorted array with duplicates. The array is originally sorted but rotated at some pivot. The task is to determine whether a given target value exists in the array. 🔎 My Approach Instead of directly jumping to complex techniques, I used a simple linear search approach: Traverse through the array from start to end. Compare each element with the target value. If a match is found, return true. If the loop finishes without finding the target, return false. 💡 Key Takeaway Sometimes starting with a simple and correct solution is important before optimizing. While more efficient approaches like modified binary search can reduce time complexity, this straightforward method helps clearly understand the problem first. ⏱ Time Complexity: O(n) Every day I’m improving my problem-solving skills in Java and Data Structures & Algorithms step by step. #Day53 #DSA #Java #ProblemSolving #CodingJourney #LeetCode #100DaysOfCode
To view or add a comment, sign in
-
-
Day 2 — Pattern-Based DSA Practice Continuing to learn and build in public while solving Data Structures & Algorithms pattern by pattern. Today's focus: Binary Search (Advanced Variations) Problems solved: • Floor in Sorted Array — GFG • Ceil in Sorted Array — GFG • First and Last Occurrence — LeetCode • Search in Rotated Sorted Array II — LeetCode • Single Element in a Sorted Array — LeetCode Key learning: Binary Search is not limited to simple searching. It can be extended to solve problems involving boundaries, duplicates, and modified sorted arrays. Each problem required slight changes in logic, but the core idea remained the same — reducing the search space efficiently. Focusing more on understanding patterns and documenting the journey consistently. #DSA #BinarySearch #LearningInPublic #Java #CodingJourney
To view or add a comment, sign in
-
🚀 Day 9 of My DSA Journey Today I solved the “Reverse Integer” problem on LeetCode using Java. This problem focuses on number manipulation, loops, and handling integer overflow, which makes it slightly tricky compared to basic problems. 💡 Problem Overview We are given a signed 32-bit integer x, and the task is to reverse its digits. Example: Input: 123 → Output: 321 Input: -123 → Output: -321 However, there is an important condition: ⚠️ If reversing the number causes it to go outside the 32-bit integer range, we must return 0. The valid integer range is: −2³¹ to 2³¹ − 1 ⚙️ Approach I Used I solved this problem using mathematical digit extraction: 1️⃣ Extract the last digit using x % 10 2️⃣ Remove the last digit from the number using x / 10 3️⃣ Build the reversed number using sum = sum * 10 + digit 4️⃣ Before adding the digit, check overflow condition using Integer.MAX_VALUE and Integer.MIN_VALUE. 📊 Complexity Analysis Time Complexity: O(log₁₀ n) Because the number of digits in n determines the number of loop iterations. Space Complexity: O(1) No extra memory is used. 📚 Key Learnings ✔ Practiced digit manipulation using modulus and division ✔ Learned how to handle integer overflow conditions ✔ Strengthened understanding of mathematical logic in algorithms 💻 Result ✅ Accepted ⚡ Runtime: 1 ms (Beats 99.88%) Small progress every day is building a strong foundation in Data Structures and Algorithms. On to Day 10 tomorrow. 💪 #DSA #LeetCode #100DaysOfCode #Java #ProblemSolving #CodingJourney #LearningInPublic #SoftwareDevelopment #Consistency
To view or add a comment, sign in
-
-
🔥 Day 347 – Daily DSA Challenge! 🔥 Problem: 📈 Non-decreasing Subsequences Given an integer array nums, return all the different non-decreasing subsequences of length ≥ 2. 💡 Key Insight — Bitmask Enumeration Instead of backtracking, we can generate all subsequences using bitmasking. If the array length is n, the total subsets are: Each mask represents a subsequence: Bit 1 → include element Bit 0 → skip element Then we simply filter valid subsequences. 🧠 Validation Step A subsequence is valid if: nums[i] ≥ nums[i-1] for all elements. We also store results in a HashSet to avoid duplicates. ⚡ Algorithm Steps ✅ Generate all subsets using bitmask (0 → 2^n - 1) ✅ Build subsequence from set bits ✅ Check: size ≥ 2 non-decreasing order ✅ Add to Set<List<Integer>> ✅ Convert set to list ⚙️ Complexity ✅ Time Complexity: O(n × 2ⁿ) (all subsets checked) ✅ Space Complexity: O(2ⁿ) 💬 Challenge for you 1️⃣ How would you solve this using backtracking instead of bitmasking? 2️⃣ Why do duplicates appear when numbers repeat? 3️⃣ How can we avoid using a HashSet? #DSA #Day347 #LeetCode #Bitmasking #Subsequences #Backtracking #Java #ProblemSolving #KeepCoding
To view or add a comment, sign in
-
-
Yesterday's problem was about searching in a rotated array. Today's challenge was slightly different: What if we just needed to find the smallest number in that rotated array? 🚀 Day 76/365 — DSA Challenge Solved: Find Minimum in Rotated Sorted Array The Problem You're given a sorted array that has been rotated at some unknown pivot. 💡 My Approach This problem can be solved using Binary Search. Key observation: In a rotated sorted array, the smallest element is where the rotation happened. Steps: 1️⃣ Find the middle element 2️⃣ Compare it with the right element: nums[mid] > nums[right] 3️⃣ If true → the minimum must be in the right half 4️⃣ Otherwise → the minimum is in the left half (including mid) Complexity ⏱ Time: O(log n) 📦 Space: O(1) Day 76/365 complete. 💻 289 days to go. Code 👇 https://lnkd.in/dad5sZfu #DSA #Java #LeetCode #BinarySearch #Algorithms #LearningInPublic
To view or add a comment, sign in
-
-
🚀 **LeetCode Problem Solved – Max Consecutive Ones III** Today I solved **Problem 1004: Max Consecutive Ones III** using the **Sliding Window technique**. 🔹 **Problem Summary** Given a binary array `nums` containing 0s and 1s and an integer `k`, we are allowed to flip at most `k` zeros to ones. The goal is to determine the **maximum number of consecutive 1s** possible after performing at most `k` flips. 🔹 **Approach** Instead of checking every possible subarray, I used the **Sliding Window (Two Pointer) approach**: • Expand the window using the right pointer • Count the number of zeros in the window • If zeros exceed `k`, move the left pointer to maintain a valid window • Track the maximum window size 🔹 **Complexity** ⏱ Time Complexity: **O(n)** 💾 Space Complexity: **O(1)** 📊 **Result** ✔ 60 / 60 Testcases Passed ⚡ Runtime: **2 ms (Beats 99.93%)** Consistent practice with **Data Structures & Algorithms** helps build strong problem-solving skills and deeper understanding of algorithmic patterns. Always open to learning better approaches or optimizations! 💡 #LeetCode #DSA #Java #SlidingWindow #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🔥 Day 353 – Daily DSA Challenge! 🔥 Problem: 🔍 Single Element in a Sorted Array Given a sorted array where every element appears twice except one, find that single element in O(log n) time. 💡 Key Insight — Binary Search on Pairs In a perfect paired array: Pairs start at even indices Pattern breaks at the single element We use binary search to detect where this pattern breaks. 🧠 Core Observation Before the single element: pairs → (even, odd) After the single element: pairs shift → (odd, even) So we normalize mid: if mid is odd → make it even ⚡ Algorithm Logic ✅ Find mid ✅ Make mid even ✅ Compare: If nums[mid] == nums[mid+1] → move right Else → move left This narrows down to the single element. ⚙️ Complexity ✅ Time Complexity: O(log n) ✅ Space Complexity: O(1) 💬 Challenge for you 1️⃣ Why do we force mid to be even? 2️⃣ How would you solve this using XOR in O(n)? 3️⃣ What if elements appear thrice except one? #DSA #Day353 #LeetCode #BinarySearch #Arrays #Optimization #Java #ProblemSolving #KeepCoding
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
Keep Going