🚀 Day 76 of #100DaysOfCode Today I solved a string manipulation problem: Clear Digits 🧠 Problem: Given a string, whenever a digit appears, remove the previous character. Digits act like a backspace operation. 💡 Key Insight: Instead of modifying the string directly (since Strings are immutable in Java), I used a StringBuilder, which works like a stack: If character → append (push) If digit → delete last character (pop) 📌 What I Learned: StringBuilder is powerful for string modifications Always handle edge cases (like digit at the start) Many string problems are actually stack problems in disguise ⏱ Complexity: Time: O(n) Space: O(n) #Java #DSA #LeetCode #CodingJourney #100DaysOfCode #ProblemSolving
Java String Manipulation with StringBuilder
More Relevant Posts
-
🚀 Day 41/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 3427. Sum of Variable Length Subarrays Used a nested loop approach to calculate subarray sums for each index by dynamically determining the starting point using max(0, i - nums[i]). ⏱️ Time Complexity: O(n²) 📦 Space Complexity: O(1) Strengthening understanding of subarray problems and index-based range calculations. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 87 – #100DaysOfCode Today I solved a problem on Maximum Number of String Pairs using HashSet. 🔹 Problem: Given an array of strings, find the number of pairs where one string is the reverse of another. 🔹 Approach I Used: Traverse through each word in the array. Reverse the current string using StringBuilder. Check if the reversed string already exists in a HashSet. If it exists → we found a pair ✅ Otherwise → store the current word in the set. 💡 Key Idea: Using a HashSet allows constant time lookup O(1) to quickly check if the reverse string already appeared. ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(n) #DSA #Java #CodingJourney #LeetCode #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 18/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 1528. Shuffle String Used a direct indexing approach by placing each character at its correct position using the given indices array. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) A simple yet important problem to strengthen understanding of arrays and index mapping. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 6/100 – LeetCode Challenge 🚀 Problem: #189 Rotate Array Difficulty: Medium Language: Java Approach: Array Reversal Technique Time Complexity: O(n) Space Complexity: O(1) 🔍 Key Insight: Instead of shifting elements one by one, the array can be rotated efficiently using a three-step reversal strategy. Steps: 1️⃣ Reverse the entire array 2️⃣ Reverse the first k elements 3️⃣ Reverse the remaining elements This achieves the required rotation in-place with constant extra space. 🧠 Solution Brief: Calculated k % n to handle cases where k is greater than array length. Reversed the entire array first. Then reversed the first k elements and the remaining n-k elements. This sequence correctly rotates the array to the right. 📌 What I Learned: Understanding patterns like array reversal can simplify problems that initially seem complex. Optimizing from brute force shifting to an in-place O(n) solution improves efficiency. #LeetCode #Day6 #100DaysOfCode #Java #DSA #Arrays #RotateArray #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
LeetCode Problem || Find Unique Binary String (1980)🚀 Today I solved the problem "Find Unique Binary String" using Java. 🔹 Problem: We are given an array of n binary strings, each of length n. The goal is to return a binary string of length n that does not exist in the array. 🔹 Approach (Diagonal Flip Technique): The idea is simple but powerful: Traverse the array using index i. Look at the i-th character of the i-th string (nums[i][i]). Flip the bit (0 → 1, 1 → 0). Append it to a result string. 💡 Time Complexity: O(n) Practicing problems like this strengthens logical thinking and problem-solving skills. #LeetCode #Java #CodingPractice #ProblemSolving #DSA
To view or add a comment, sign in
-
-
Day 56 of #100DaysOfLeetCode 💻✅ Solved #205. Isomorphic Strings problem in Java. Approach: • Used two arrays to track character mappings for both strings • Traversed both strings simultaneously • Checked if the mapping values at current characters are equal • If not equal, returned false (mapping mismatch) • Updated both arrays with the current index + 1 • This ensures consistent one-to-one mapping between characters Performance: ✓ Runtime: 8 ms (Beats 72.19% submissions) ✓ Memory: 44.16 MB (Beats 22.15% submissions) Key Learning: ✓ Learned how to maintain mapping consistency between two strings ✓ Practiced using arrays for character indexing ✓ Strengthened understanding of string pattern matching problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 2 of my #365DaysCodingChallenge | CodeOjas Journey Today, I solved 3 interesting array-based problems using Java: 🔹 Unique Subarray Sum Pairs – Found pairs of subarrays with equal sums using hashing techniques. 🔹 Array Rotation – Rotated array efficiently using optimized reversal approach. 🔹 Shifted Array – Implemented element shifting with proper handling of wrap-around using modular arithmetic. 💡 Approach: Focused on breaking problems into smaller parts, using concepts like subarrays, indexing, and optimization techniques. ⚡ Complexity: Most solutions were optimized to O(n) time with minimal space. 📌 Takeaway: Strong understanding of array manipulation and problem breakdown is key to solving DSA problems efficiently. Building consistency and improving every day 💪🔥 📂 Code: [Your GitHub Link] #DSA #Java #CodeOjas #365DaysOfCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
Day 14/100 – LeetCode Challenge 🚀 Problem: #169 Majority Element Difficulty: Easy Language: Java Approach: Sorting + Middle Element Time Complexity: O(n log n) Space Complexity: O(1) 🔍 Key Insight: The majority element appears **more than ⌊n / 2⌋ times** in the array. If we **sort the array**, the majority element must occupy the **middle position** because it appears more than half of the time. Therefore, the element at index **n/2** will always be the majority element. 🧠 Solution Brief: First sorted the array using `Arrays.sort()`. Since the majority element appears more than half of the array length, it will always be positioned at the middle index. Finally returned `nums[nums.length / 2]` as the majority element. 📌 What I Learned: Understanding problem constraints can simplify the solution significantly. Sometimes a simple observation (like majority occupying the middle after sorting) can avoid more complex implementations. #LeetCode #Day14 #100DaysOfCode #Java #DSA #Arrays #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
LeetCode Problem || Minimum Changes To Make Alternating Binary String (1758)🚀 Binary String. 🔹 Problem Summary: Given a binary string s containing only 0 and 1, we need to find the minimum number of changes required to make the string alternating (no two adjacent characters should be the same). Example of valid alternating strings: 0101, 1010 🔹 Key Idea: An alternating string can only have two possible patterns: 1️⃣ Starting with 0 → 010101... 2️⃣ Starting with 1 → 101010... So the approach is: Count mismatches if the string follows pattern 0101... Count mismatches if the string follows pattern 1010... The minimum of the two counts is the answer Time Complexity:O(n) Space Complexity:O(1) #LeetCode #DSA #Java #ProblemSolving #CodingPractice
To view or add a comment, sign in
-
-
🚀 Day 31/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 69. Sqrt(x) Used the Binary Search approach to find the integer square root without using built-in power functions. The search space is reduced by checking mid * mid against x. ⏱️ Time Complexity: O(log n) 📦 Space Complexity: O(1) Strengthening problem-solving skills with binary search patterns on answer space. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
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