Day 6 of Daily DSA 🚀 Solved LeetCode 27: Remove Element ✅ Approach: Used a two-pointer technique to modify the array in-place. Traversed the array once and shifted all valid elements to the front. No extra space used — clean and efficient. Complexity: • Time: O(n) • Space: O(1) LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.54 MB This problem reinforced a key DSA lesson: 👉 In-place solutions + pointers #DSA #LeetCode #Java #TwoPointers #ProblemSolving #Consistency #DailyCoding
LeetCode 27: Remove Element in-place with Two Pointers
More Relevant Posts
-
Day 16 of Daily DSA 🚀 Solved LeetCode 75: Sort Colors ✅ Approach: Used the Dutch National Flag algorithm with three pointers. start → tracks position for 0s mid → current element end → tracks position for 2s By swapping elements in-place, the array is sorted in one pass without using any built-in sort. ⏱ Complexity: • Time: O(n) — single traversal • Space: O(1) — in-place sorting 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.63 MB (Beats 42.09%) A classic problem that perfectly demonstrates pointer-based thinking. #DSA #LeetCode #Java #BinarySearch #TwoPointers #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 22 of Daily DSA 🚀 Solved LeetCode 66: Plus One ✅ Approach: Treat the array as a number and simulate addition from the last digit: • If the last digit is not 9, increment and return • Handle carry by setting 9 → 0 and moving left • If all digits are 9, create a new array with leading 1 This avoids converting the array into an integer and handles large numbers safely. ⏱ Complexity: • Time: O(n) • Space: O(1) (extra array only when overflow happens) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.58 MB (Beats 38.49%) A simple problem that tests edge-case thinking 💡 #DSA #LeetCode #Java #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 10 of Daily DSA 🚀 Solved LeetCode 190: Reverse Bits ✅ 🔍 Approach: Worked with the 32-bit representation of the given integer: • Converted the number into a fixed 32-bit binary string • Used a two-pointer technique to reverse the bits • Converted the reversed binary back to an unsigned integer This approach keeps the logic simple while ensuring correctness for signed integers. ⏱ Complexity: • Time: O(32) = O(1) (constant time) • Space: O(32) = O(1) 📊 LeetCode Stats: • Runtime: 9 ms • Memory: 43.46 MB A good reminder that clarity matters more than micro-optimizations when learning bit manipulation. #DSA #LeetCode #Java #BitManipulation #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 12 of Daily DSA 🚀 Solved LeetCode 704: Binary Search ✅ Approach: Used the classic binary search technique on a sorted array. Initialized start and end pointers and repeatedly narrowed the search space by comparing the target with the middle element. Calculated mid using start + (end - start) / 2 to avoid overflow and ensure correctness. This approach efficiently reduces the search range and guarantees optimal performance. ⏱ Complexity: • Time: O(log n) — search space halves every iteration • Space: O(1) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 48.54 MB (Beats 29.13%) A solid example of how understanding fundamentals leads to maximum efficiency. #DSA #LeetCode #Java #BinarySearch #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
🚀 Day 16 of solving DSA problems 🧠 Problem: Majority Element Today I learned a powerful algorithm called 👉 Boyer–Moore Voting Algorithm Key Insight: Instead of counting frequency using HashMap, we can cancel out different elements. Since majority element appears > n/2 times, it can never be fully cancelled. ⏱ Complexity: Time → O(n) Space → O(1) 💡 Lesson: Always check problem constraints — if majority is guaranteed, we can use optimized logic instead of extra memory. Consistency is the real key to mastering DSA. 🔥 #DSA #Java #CodingJourney #ProblemSolving #LearningInPublic
To view or add a comment, sign in
-
-
Day 11 of Daily DSA 🚀 Solved LeetCode 1800: Maximum Ascending Subarray Sum ✅ 🔍 Approach: Iterated through the array while maintaining the sum of the current strictly increasing subarray. Whenever the sequence breaks, a new subarray sum is started and stored. Finally, the maximum subarray sum is obtained from the stored values. This method clearly separates each ascending subarray and helps in understanding the problem flow. ⏱ Complexity: • Time: O(n) — single traversal + max lookup • Space: O(n) — list used to store subarray sums 📊 LeetCode Stats: • Runtime: 1 ms ⚡ • Memory: 43.30 MB A good learning step before optimizing further to constant space. #DSA #LeetCode #Java #Arrays #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 26 of Practicing DSA on LeetCode Solved: • (1351) Count Negative Numbers in a Sorted Matrix – Easy Focused on: -Leveraging row-wise sorted property -Breaking early once a negative number is found -Reducing unnecessary iterations -Thinking about how this could be optimized further using binary search This problem reinforced that understanding data structure properties reduces time complexity naturally. Use the structure. Trust the pattern. Consistency over everything. #DSA #Java #LeetCode #BinarySearch #Matrix #ProblemSolving #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
Day 7 of Daily DSA 🚀 Solved LeetCode 167: Two Sum II – Input Array Is Sorted Approach: Used the two-pointer technique leveraging the sorted nature of the array. Moved pointers inward based on the comparison with the target to find the answer in one pass. Complexity: • Time: O(n) • Space: O(1) (constant extra space) LeetCode Stats: • Runtime: 2 ms (Beats 96.10%) • Memory: 48.54 MB (Beats 38.87%) This problem highlights how understanding input constraints can turn a brute-force solution into an optimal one. #DSA #LeetCode #Java #TwoPointers #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 4 of DSA Practice 🚀 Today I solved two classic problems focused on the two-pointer technique. 1️⃣ 3Sum (LeetCode 15) Tried two approaches: -Sorting + HashMap -Sorting + Two Pointers (optimal) Time Complexity: O(n²) Space Complexity: O(n) (HashMap) / O(1) (Two pointers, excluding result) Really understood how sorting simplifies the logic and helps control pointer movement efficiently. 2️⃣ Container With Most Water (LeetCode 11) Used the greedy two-pointer approach. Time Complexity: O(n) Space Complexity: O(1) Key learning: When width keeps shrinking, the only way to maximize area is to move the pointer with the smaller height. Consistency is starting to pay off 💪 #Day4 #DSA #LeetCode #Java #ProblemSolving #TwoPointers#PlacementPreparation
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