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
LeetCode 917: Reverse Only Letters in Java with Two Pointers
More Relevant Posts
-
🚀 Day 38 of #100DaysOfLeetCode Today I solved "Container With Most Water" problem on LeetCode. 🔹 Difficulty: Medium 🔹 Concept Used: Two Pointer Technique 🔹 Language: Java 📌 Problem Summary: Given an array representing heights of vertical lines, the goal is to find two lines that together with the x-axis can contain the maximum amount of water. 💡 Approach: Instead of checking all possible pairs (O(n²)), I used the Two Pointer approach which reduces the time complexity to O(n). Steps: 1️⃣ Start with two pointers at the beginning and end of the array. 2️⃣ Calculate the area using the smaller height. 3️⃣ Move the pointer with the smaller height inward. 4️⃣ Track the maximum area during each step. 📊 Result: ✅ Runtime: 5 ms (Beats 81.86%) ✅ Memory: Beats 95.54% This problem was a great exercise to understand optimization using two pointers instead of brute force. Consistency is the key — moving forward one problem at a time! 💪 #LeetCode #100DaysOfCode #Java #DSA #CodingChallenge #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 2/100 – LeetCode Challenge 🚀 Problem: #48 Rotate Image Difficulty: Medium Language: Java Approach: In-Place Rotation using Transpose + Row Reversal Time Complexity: O(n²) Space Complexity: O(1) 🔍 Key Insight: To rotate a matrix 90° clockwise without extra space: 1️⃣ First transpose the matrix (swap across diagonal). 2️⃣ Then reverse each row. This avoids creating a new matrix and satisfies the in-place constraint. 🧠 Solution Brief: Used nested loops to transpose the matrix by swapping arr[i][j] and arr[j][i]. Then reversed each row using two pointers (start and end). Combined both operations inside a rotate() method. Achieved full rotation with constant extra space. 📌 What I Learned: Matrix problems are more about pattern recognition than brute force. Understanding transformations (transpose + reverse) makes complex problems simple. Starting my 100 Days of LeetCode journey today 💪 Consistency > Motivation. #LeetCode #Day2 #100DaysOfCode #Java #DSA #Matrix #ProblemSolving #CodingJourney #MediumProblem
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
-
-
🚀 #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 15 of My LeetCode Journey 🧩 Problem Solved: 1980. Find Unique Binary String 💻 Language: Java Today I worked on a problem where we are given n unique binary strings, each of length n, and we need to find another binary string of length n that does not exist in the list. 🔍 Key Insight: Instead of checking all possible binary combinations, we can build a new string by flipping the i-th bit of the i-th string. This guarantees the new string will differ from every string in the array at least at one position. ⚡️ Concept Used: Diagonalization technique 📈 Time Complexity: O(n) 📦 Space Complexity: O(n) 💡 This problem reminded me that sometimes the smartest solutions come from simple observations rather than brute force approaches. Consistency is key — solving problems daily to strengthen my Java and problem-solving skills. #LeetCode #Java #CodingJourney #ProblemSolving #100DaysOfCode #DataStructures #LearningInPublic
To view or add a comment, sign in
-
-
🚀 LeetCode Day 18 – Complement of Base 10 Integer Today I solved LeetCode Problem 1009: Complement of Base 10 Integer using Java. 🧠 Problem: Given a non-negative integer n, return the complement of its binary representation. The complement means flipping all bits in the binary form of the number. 📌 Example: Input: n = 5 Binary of 5 → 101 Complement → 010 Output → 2 💡 Approach: • Create a bitmask with all bits set to 1 up to the highest bit of n. • Use the XOR (^) operator with the mask to flip the bits. 💻 Java Code: class Solution { public int bitwiseComplement(int n) { if (n == 0) return 1; int mask = 0, temp = n; while (temp > 0) { mask = (mask << 1) | 1; temp >>= 1; } return n ^ mask; } } ⏱️ Time Complexity: O(log n) 📦 Space Complexity: O(1) 📚 Practicing Data Structures & Algorithms daily to improve problem-solving skills. #LeetCode #Java #DSA #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 77 of 100: LeetCode Challenge – One Step Closer! 🚀 🎯 Problem: Combination Sum II 💡 Difficulty: Medium 🛠️ Language: Java 📌 Today’s win: Solved "Combination Sum II" — a follow-up to the previous combination problem, but this time with duplicates in the input and each number used only once per combination. 🧠 Approach: Sorted the array to handle duplicates easily Used backtracking with a "start" index to avoid reusing the same element Skipped duplicates during recursion to prevent repeated combinations 📊 Runtime: 8 ms (Beats 16.56%) 📦 Memory: 50.53 MB (Beats 5.73%) ✅ Passed all 176 test cases! 🔍 Key Takeaways: Sorting + backtracking is a classic combo for subset/combination problems Skipping duplicates in recursion is essential to avoid redundant results The "remain < 0" condition helps prune the search tree early 📈 74 days down, 26 to go — consistency is the real win! #LeetCode #100DaysOfCode #Java #CodingChallenge #Backtracking #CombinationSumII #ProblemSolving #CodeNewbie #DevCommunity #WomenWhoCode #LearnInPublic #DSA
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
-
-
Day 30 of #100DaysOfLeetCode 💻✅ Solved #108. Convert Sorted Array to Binary Search Tree on LeetCode using Java. Approach: • Used Divide and Conquer strategy • Selected the middle element as the root to maintain balance • Recursively built the left subtree using left half of array • Recursively built the right subtree using right half of array • Ensured the tree remains height-balanced at every step Performance: ✓ Runtime: 0 ms (Beats 100.00% submissions) ✓ Memory: 45.18 MB (Beats 44.10% submissions) Key Learning: ✓ Understood how sorted arrays can directly map to balanced BST ✓ Strengthened recursion fundamentals in tree construction ✓ Improved understanding of height-balanced binary trees Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinarySearchTree #Recursion #DivideAndConquer #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Strings look simple until edge cases show up 👀 Day 8 / #100DaysOfCode 🚀 Solved: Valid Palindrome (LeetCode 125) 🔹 Approach: Used the two-pointer technique starting from both ends. Ignored non-alphanumeric characters and compared characters after converting the string to lowercase. Time Complexity: O(n) Space Complexity: O(1) ✔ Practiced string traversal with pointers ✔ Handled real-world edge cases (spaces, symbols, cases) ✔ Avoided extra space by working in-place 💡 Takeaway: Clean pointer logic often beats preprocessing with extra data structures. Building strong fundamentals in Java, one problem at a time. #LearnInPublic #100DaysOfCode #DSA #Java #Strings #ProblemSolving #SoftwareEngineer #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