Day36 - LeetCode Journey Solved LeetCode 541: Reverse String II in Java ✅ This one was all about careful indexing and pattern-based string manipulation. The idea of processing the string in blocks of 2k characters and selectively reversing only the first k in each block really tests attention to detail. Using a two-pointer approach inside each segment made the logic clean and easy to follow, while handling edge cases like shorter remaining substrings kept things interesting. Key takeaways: • Stronger grasp on string traversal in fixed-size blocks • Effective use of two pointers for in-place reversal • Handling boundary conditions without extra space • Writing efficient and readable string logic Another small problem, another solid concept reinforced. Consistency really compounds over time 💪 #LeetCode #DSA #Java #Strings #TwoPointers #Algorithms #ProblemSolving #CodingPractice #InterviewPreparation #DailyCoding
Reversing Strings in Java with Two Pointers
More Relevant Posts
-
Day 44 - LeetCode Journey Solved LeetCode 917: Reverse Only Letters in Java ✅ A clean two-pointer problem that really tests your understanding of string manipulation. The goal was simple: reverse only the letters while keeping all non-letter characters in their original positions. Instead of creating extra data structures, I used two pointers from both ends. If a character is not a letter, we skip it. When both pointers land on letters, we swap them. This continues until the pointers meet. What I liked about this problem is how it teaches you to control movement smartly rather than brute forcing the solution. Key takeaways: • Two-pointer technique for efficient traversal • Handling edge cases (symbols, numbers) • Writing in-place logic without extra space • Clean and readable code ✅ All test cases passed ✅ 100% runtime performance Problems like this improve your thinking for real interview scenarios where optimization matters. #LeetCode #DSA #Java #Strings #TwoPointers #Algorithms #ProblemSolving #CodingJourney #InterviewPrep #Consistency
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode | Day 35 📌 LeetCode : Minimum Depth of Binary Tree Today I solved the Minimum Depth of Binary Tree problem using Java. The goal was to find the shortest path from the root node to the nearest leaf node. I applied a recursive approach while carefully handling edge cases where one subtree is null. Instead of directly taking the minimum of both sides, I ensured the solution correctly skips null paths to avoid incorrect depth calculations. 📌 Key takeaways: 🔹 Understood the difference between minimum and maximum depth logic 🔹 Learned the importance of handling null child nodes 🔹 Strengthened recursion and tree traversal concepts 🔹 Improved problem-solving accuracy in edge cases This problem helped me think more clearly about tree structures and reinforced the importance of precise base conditions in recursion. #Java #LeetCode #DSA #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 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
To view or add a comment, sign in
-
-
🚀 Day 89 of My 100 Days LeetCode Challenge | Java Today’s problem was an interesting mix of string manipulation, sliding window, and pattern matching. The challenge was to determine the minimum number of flips required to convert a binary string into an alternating sequence, considering that the string can also be rotated. At first glance it feels like a simple flipping problem, but rotation adds another layer of complexity. The key idea was to simulate all rotations efficiently by doubling the string and using a sliding window to track mismatches against alternating patterns. Instead of checking every rotation individually, this approach allows us to compute the answer in linear time. ✅ Problem Solved: Minimum Number of Flips to Make the Binary String Alternating ✔️ All test cases passed (65/65) ⏱️ Runtime: 19 ms 🧠 Approach: Sliding Window + Pattern Matching 🧩 Key Learnings: ● Rotations can often be simulated by doubling the string. ● Sliding window techniques help avoid recomputation. ● Comparing with expected patterns simplifies mismatch counting. ● Efficient string handling is crucial for optimization problems. ● Sometimes the trick is not the operation itself, but how you simulate it efficiently. This problem was a great reminder that smart transformations can turn complex problems into linear-time solutions. 🔥 Day 89 complete — improving my understanding of sliding window techniques and string optimizations. #LeetCode #100DaysOfCode #Java #SlidingWindow #Strings #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 34 of #100DaysOfLeetCode 💻✅ Solved #110. Balanced Binary Tree on LeetCode using Java. Approach: • Used a bottom-up recursive approach to calculate height • Returned -1 immediately if any subtree is unbalanced • Compared left and right subtree heights at each node • Checked if the height difference is greater than 1 • Stopped early to optimize unnecessary computations Performance: ✓ Runtime: 0 ms (Beats 100.00% submissions) ✓ Memory: 45.33 MB (Beats 95.41% submissions) Key Learning: ✓ Understood how to combine height calculation with balance checking ✓ Learned early termination technique in recursion ✓ Improved problem-solving for tree-based recursive problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTree #Recursion #TreeProblems #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 46: Binary Addition from scratch! 🔢 Problem 67: Add Binary Java's BigInteger is a thing, but manual bit manipulation is just more satisfying. My approach: 1. Padded both strings to the same length using character arrays. 2. Simulated schoolbook addition from right to left. 3. Used % 2 for the result bit and / 2 for the carry. It’s a clean O(N) solution that avoids overflow and keeps the logic transparent. No shortcuts, just pure logic. 🚀 #LeetCode #Java #Binary #Algorithms #CodingChallenge #ProblemSolving
To view or add a comment, sign in
-
-
100 Days of Coding Challenge – Day 16 📌 Problem: Roman to Integer 💻 Language: Java 🧠 Concept Used: HashMap + Conditional Traversal 🔍 Platform: LeetCode Today’s challenge was converting a Roman numeral into its integer representation. Approach: ✔ Stored Roman symbols and values in a HashMap ✔ Traversed the string from left to right ✔ If the current value is smaller than the next → subtract ✔ Otherwise → add Time Complexity: O(n) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/g2YTaPrG 🔗 Code: https://lnkd.in/g7e_Y7V7 #100DaysOfCode #Day16 #Java #DSA #LeetCode #Strings #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day41 - LeetCode Journey Solved LeetCode 821: Shortest Distance to a Character in Java ✅ Today’s problem was a great reminder that even simple-looking string questions can test how clearly you think. The goal was to find the shortest distance from every character in a string to a given target character. Sounds straightforward, but doing it efficiently is the real challenge. Instead of checking every position again and again, I used a smart two-pass approach. First pass from left to right to track the last seen occurrence. Second pass from right to left to ensure we capture the closest distance from both directions. Taking the minimum from both sides gave a clean and optimal solution. What I liked about this problem is how it trains you to think beyond brute force and focus on pattern recognition. Key takeaways: • Importance of multi-pass traversal in strings • Precomputing values to avoid unnecessary comparisons • Writing clean and readable logic • Thinking in terms of distance and optimization ✅ All test cases passed ✅ Improved confidence in string traversal patterns Small optimizations like these make a big difference in interviews. Staying consistent and sharpening fundamentals every day 💪 #LeetCode #DSA #Java #Strings #Algorithms #ProblemSolving #CodingJourney #InterviewPreparation #Consistency
To view or add a comment, sign in
-
-
Day 29 – DSA Journey 🚀 | Strings As part of my daily DSA practice, I worked on a simple yet important string problem from LeetCode that helped me understand how strings can be represented and compared in different forms. 📌 Problem Practiced: Check If Two String Arrays Are Equivalent 🔍 Core Idea: Each array represents a string formed by concatenating its elements in order. By joining all strings from both arrays and comparing the final results, we can easily determine whether they represent the same string. 📌 Concepts Applied: • String concatenation using StringBuilder • Iterating through string arrays • Understanding string immutability in Java • Comparing strings using .equals() • Writing clean and readable code 💡 Key Insight: Using StringBuilder makes string concatenation efficient and avoids unnecessary overhead caused by repeated string creation in loops. ⏱️ Time Complexity: O(n + m) 📦 Space Complexity: O(n + m) Practicing such foundational string problems is helping me gain confidence in handling input transformations and choosing the right tools for the job. One step at a time, staying consistent 🚀 #Day29 #DSAJourney #LeetCode #Strings #Java #ProblemSolving #LogicBuilding #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day -10/100 #100DaysOfLeetCode 📌Problem-1 : Find the Index of the First Occurrence in a String. 🔗Problem Link : https://lnkd.in/gp6NbvNR 💡 Approach: To solve this problem, I needed to find the first occurrence of the substring needle inside the string haystack. 🔹 First, I checked whether haystack contains needle using the built-in contains() method. 🔹 If it exists, I returned the starting index using indexOf(). 🔹 If it does not exist, I returned -1. This approach ensures a simple and efficient solution by leveraging Java’s built-in string methods. #JavaProgramming #LeetCode #ProblemSolving #CodingJourney
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