🌟 Day 41 of #100DaysOfCode 🌟 🔍 Exploring String Reversal — Simplicity in Motion 🔹 What I Solved Today’s challenge focused on one of the most fundamental yet essential problems — reversing a string in-place. No shortcuts, no helper strings — just clean pointer manipulation and precision. 🧩 Problem: Reverse a String (In-Place) 💡 Problem Statement Given an array of characters s, reverse it in-place. You must modify the input array directly, without using any extra memory. 💡 Example 1: Input: ["h","e","l","l","o"] → Output: ["o","l","l","e","h"] 💡 Example 2: Input: ["H","a","n","n","a","h"] → Output: ["h","a","n","n","a","H"] 🧠 Concepts Used Two-Pointer Technique 🔁 In-Place Array Manipulation Constant Space Optimization ⚙️ Approach 1️⃣ Use two pointers — one at the start (left) and one at the end (right). 2️⃣ Swap characters at both ends. 3️⃣ Move both pointers toward the center until they meet. 🚀 What I Learned ✨ Two-pointer techniques make complex tasks effortless. ✨ In-place operations strengthen logic and memory efficiency. ✨ Simplicity is often the most elegant form of problem-solving. 💬 Reflection Today’s challenge was a reminder that mastery begins with fundamentals. Sometimes, the most impactful solutions are built on clear, minimal logic — where simplicity meets efficiency. #100DaysOfCode #Day41 #ReverseString #TwoPointer #DSA #Java #LeetCode #Algorithm #ProblemSolving #CleanCode #ProgrammingJourney #MindfulCoding #CodeOptimization #StringManipulation
Reversing a String in-Place with Two-Pointer Technique
More Relevant Posts
-
🔥 Day 33/100 of #100DaysOfCode - Alternating Positive & Negative! Today's Problem: Rearrange Array Elements by Sign Task: Given an array with equal number of positive and negative integers, rearrange them in alternating positive/negative order (starting with positive). Solution: Used a two-pointer approach with separate indices for positive and negative positions! Created a temp array and placed positives at even indices (0, 2, 4...) and negatives at odd indices (1, 3, 5...). Key Insights: Since the array has equal positives and negatives, we can pre-determine positions O(n) time complexity with O(n) space for the temp array Clean and intuitive - no complex swapping needed Smart Pointer Management: Positive pointer moves by +2 each time Negative pointer moves by +2 each time Single pass through the original array Elegant solution for maintaining relative order while achieving the required alternation! ⚡ #100DaysOfCode #LeetCode #Java #Algorithms #Arrays #TwoPointers #CodingInterview
To view or add a comment, sign in
-
-
🚀 Day 8 of #45DaysOfLeetCode Challenge 😎 📌Today's problem: Palindrome Number (LeetCode #9) 💡 🔹 Concept: Check whether a given integer reads the same backward and forward — without converting it to a string! 🔹 Logic Used: Instead of reversing the entire number, I reversed only half of it to improve efficiency. This avoids unnecessary computation and eliminates integer overflow risks. 🔹 Key Learnings: ✅ Optimized logic using mathematical manipulation ✅ Improved understanding of number reversal techniques ✅ Importance of edge case handling (negative numbers, trailing zeros) ⚙️ Result: 💻 Runtime: 4 ms (Beats 100%) 💾 Memory: 44.84 MB 😎Small optimizations make a big difference in performance! 💪 📌Problem: https://lnkd.in/ef6AC2j6 🔥Each day is a step closer to writing cleaner and more optimized code. ✨ Let’s keep pushing forward and refining our problem-solving skills! 💻🔥 #LeetCode #Day8 #100DaysOfCode #ProblemSolving #Java #CodingChallenge #PalindromeNumber #DataStructures #Algorithms #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Problem 2: Reverse Integer 💡 Leetcode Problem No: 7 Today, I solved an interesting Leetcode-style problem that involves reversing an integer — while handling tricky cases like integer overflow 🔄 ✨ Challenge: Given an integer x, reverse its digits and return the reversed number. If reversing x causes the value to go outside the signed 32-bit integer range, return 0. 💻 Key Learnings: 🔹 Used Math.abs(x) to handle negatives elegantly 🔹 Applied overflow check using: if (rev > (Integer.MAX_VALUE - d) / 10) 🔹 Mastered modulus (%) and division (/) logic for digit extraction 🔹 Ensured both positive and negative numbers are correctly reversed 💙 Tip: Always consider edge cases and overflow conditions when working with integer manipulation problems. #Java #Coding #LeetCode #ProblemSolving #JavaDeveloper #ProgrammingChallenge #LeetcodeCoding
To view or add a comment, sign in
-
-
💡 Day 19 of My LeetCode Journey — 3Sum Closest Today’s problem was “3Sum Closest”, a slight twist on the classic 3Sum challenge. 🧩 Problem Statement: Given an integer array nums and a target value, find three integers whose sum is closest to the target. Return the sum of those three numbers. Example: Input: nums = [-1, 2, 1, -4], target = 1 Output: 2 Explanation: (-1 + 2 + 1 = 2) ⚙️ Approach: Sort the array for easy pointer movement. Use a for loop to fix one element at a time. Apply the two-pointer technique to find the closest sum. Compare differences using Math.abs() to track which combination is nearer to the target. 📘 Key Learning: 🔹 Sorting simplifies pointer logic. 🔹 Math.abs() is crucial for measuring closeness. 🔹 Sometimes, you don’t need the exact answer — just the closest one. #30DaysOfCode #LeetCode #Java #CodingJourney #ProblemSolving #DataStructures #Algorithms #TwoPointers #TechLearning
To view or add a comment, sign in
-
-
📌 Day 159 of Coding - Make Array Elements Equal to Zero (LeetCode - Easy) 🎯 Goal: Given an integer array nums, find the number of valid starting positions and directions such that by repeatedly decrementing and reversing direction (based on the rules), all elements eventually become 0. 💡Approach & Debugging: First computed total sum using Arrays.stream(nums).sum(). Maintained two prefix sums : left and right. For each index i where nums[i] == 0: Incremented left and decremented right progressively. Checked whether the left and right sums balance according to the movement rules. Counted valid selections when the balance was perfect or off by just one. ✔️ Time Complexity: O(N) - single pass through the array. ✔️ Space Complexity: O(1) - constant extra space. #Day159 #LeetCode #Simulation #Arrays #PrefixSum #Java #ProblemSolving #DSA #CodingChallenge #100DaysOfCode #Algorithms #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
📌 Day 154 of Coding - Check If Digits Are Equal in String After Operations I (LeetCode - Medium) 🎯 Goal: Given a numeric string s, repeatedly replace it with a new string formed by taking the sum (mod 10) of every pair of adjacent digits, until only two characters remain. Return whether the final two digits are equal. 💡Approach & Debugging: Used a simple iterative simulation approach. For each iteration, formed a new string res by summing adjacent digits modulo 10. Replaced s with res and continued until the string length dropped to 2. Finally, compared both digits for equality. ✔️ Time Complexity: O(N*N) - since the string shrinks gradually each iteration. ✔️ Space Complexity: O(N) - temporary strings. 🧠 Key Takeaways: Some problems test simulation and string manipulation more than algorithms. Always track how input size evolves after each iteration. #Day154 #LeetCode #StringManipulation #Java #ProblemSolving #DSA #CodingChallenge #Algorithms #100DaysOfCode #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
Day 18 — Frequency Boost Mode ON! Problem: 3346. Maximum Frequency of an Element After Performing Operations I Difficulty: Medium Today’s problem was all about maximizing the frequency of an element in an array — but with a twist 🔄. You can tweak elements up or down by up to k, but only for a limited number of operations. The challenge? Figuring out how to best use those operations to make one number appear the most times possible. It’s a mix of prefix sums, counting frequency, and a bit of greedy optimization — perfect for sharpening problem-solving intuition. Takeaway: Sometimes, optimization isn’t about making everything perfect — it’s about finding where a few smart changes make the biggest difference. #Day18 #LeetCode #Java #ProblemSolving #100DaysOfCode #CodingChallenge #LeetCodeMedium #DataStructures #Algorithms
To view or add a comment, sign in
-
-
🚩 Problem: 153. Find Minimum in Rotated Sorted Array 🔥 Day 59 of #100DaysOfLeetCode 🔍 Problem Summary: You’re given a rotated sorted array of unique integers. Your task: find the minimum element in O(log n) time. Example of rotated array: [4,5,6,7,0,1,2] → minimum = 0 🧠 Intuition: Because the array is originally sorted, rotation keeps two sorted halves. We can use binary search: Check if the mid element is part of the right sorted half Or the left sorted half Narrow down the search to where the rotation break happens The minimum is exactly at the rotation point Key observation: If nums[mid] > nums[right] → min is in the right half Else → min is in the left half Clean, elegant, and strictly log-time.⚙️ Performance: ⏱️ Runtime: 0 ms 🚀 💪 Beats: 100% of Java solutions 💾 Memory: 42 MB ⚡ (Beats 95%+ users) 📊 Complexity: Time Complexity: O(log n) Space Complexity: O(1) ✨ Key Takeaway: This is the perfect example of using binary search on conditions, not just sorted arrays. Mastering this pattern helps solve advanced problems on rotated arrays and search intervals. Link:[https://lnkd.in/ggdZwAKJ] #100DaysOfLeetCode #Day59 #Problem153 #FindMinimumInRotatedArray #BinarySearch #Algorithms #DSA #Java #CodingChallenge #ProblemSolving #LeetCode #InterviewPreparation #CrackingTheCodingInterview #BinarySearchPattern #CodingCommunity #SoftwareEngineering #DataStructures #DeveloperJourney #ArjunInfoSolution #TechCareers #CareerGrowth #Programming #ZeroToHero #LearnToCode #CodeNewbie #CodingIsFun #JavaDeveloper #GameDeveloper #Unity #AI #MachineLearning
To view or add a comment, sign in
-
-
📌 Day 160 of Coding - Reconstruct a 2-Row Binary Matrix (LeetCode - Medium) 🎯 Goal: Reconstruct a 2-row binary matrix given the sums of each column (colsum), and total ones allowed in the upper and lower rows (upper, lower). 💡Approach & Debugging: Used a greedy approach to fill the matrix step by step while maintaining constraints. Steps: Traverse all columns: If colsum[i] == 2, both rows must have 1. Decrease both upper and lower. Traverse again for colsum[i] == 1: Assign 1 to the row with remaining quota (upper first, else lower). If any quota (upper or lower) remains after processing, return an empty list (invalid configuration). Otherwise, return the constructed matrix. ✔️ Time Complexity: O(N) - single traversal of the array. ✔️ Space Complexity: O(N) - to store the two rows. #Day160 #LeetCode #GreedyAlgorithm #Matrix #ProblemSolving #Java #CodingChallenge #DSA #Algorithms #100DaysOfCode #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
Explore related topics
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