📌 Day 24/100 - Maximum Points You Can Obtain from Cards (LeetCode 1423) 🔹 Problem: You’re given an array of card points where each card has some value. You can take exactly k cards — but only from the beginning or end of the row. The goal is to maximize your total score. 🔹 Approach: This problem is a perfect case for the sliding window technique. Start by taking the sum of the first k cards (left side). Then, gradually move one card from the left side to the right side — each time removing one card from the start and adding one from the end. Track the maximum sum at each step. ✅ This gives an O(k) time solution — efficient and clean! 🔹 Key Learning: Use sliding window when you need to balance two ends dynamically. Prefix sums aren’t always needed — direct window manipulation works wonders. Optimization often lies in reducing repeated work, not complex math. A simple yet powerful logic: “Take, replace, compare — repeat!” #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #SlidingWindow #CodingJourney
Maximizing Card Points with Sliding Window Technique
More Relevant Posts
-
🚀 Day 12 of #50DaysOfLeetCodeChallenge 🚀 🧩 Problem 1260: Shift 2D Grid:: You are given a 2D grid of size m x n and an integer k. The task is to shift the grid k times. 💡 Approach: Flattened the 2D grid into a 1D array to simplify shifting. Calculated the effective shifts using k % totalElements to avoid redundant rotations. Created a new shifted array by mapping each element from the original flattened array to its new position. Converted the 1D shifted array back into a 2D array row by row. ✅ Efficient: O(m * n) ✅ Handles all edge cases, including k = 0 or k > total elements ✅ Clear and easy-to-follow logic 📚 Key Takeaways: Strengthened understanding of 2D to 1D mapping and vice versa. Learned how modular arithmetic helps in rotation problems. Improved skills in array transformations and index calculations. Huge thanks to Trainer Shishir chaurasiya and PrepInsta for constant guidance and motivation! 🙏 #50DaysOfLeetCodeChallenge #LeetCode #Java #ProblemSolving #CodingJourney #TechCommunity #KeepLearning #DSA
To view or add a comment, sign in
-
-
💻 Day 11 of #100DaysOfLeetCode – Rotate Image Today’s challenge was “Rotate Image”, a classic matrix manipulation problem that tests both logic and spatial reasoning. 🔹 Problem Statement: Given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise) — all in place, without using extra memory for another matrix. 🔹 My Approach (in Java): I used a two-step in-place transformation technique: 1️⃣ Transpose the matrix — swap elements across the diagonal (matrix[i][j] ↔ matrix[j][i]). 2️⃣ Reverse each row — to achieve the 90° clockwise rotation. This approach ensures O(1) extra space and O(n²) time complexity, which is optimal for this problem. 🔹 Key Takeaways: ✅ Learned how matrix transformations can be broken down into simpler operations. ✅ Improved understanding of in-place algorithms and memory efficiency. ✅ Reinforced clean coding habits and edge case handling. Every rotation brings me one step closer to mastering problem-solving patterns! 💪 #100DaysOfLeetCode #CodingJourney #RotateImage #Java #DSA #ProblemSolving #LeetCode #CodingChallenge #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 414 of #500DaysOfCode 🔢 LeetCode 2536: Increment Submatrices by One (Medium) Today I worked on an interesting matrix manipulation problem that teaches an important optimization idea — 2D Difference Arrays. 🧠 Problem Summary We are given an n x n matrix initialized with zeros and a list of queries. Each query represents a submatrix, and we need to increment every element inside that submatrix by 1. A brute-force solution would update each cell for every query, which becomes inefficient when the matrix and number of queries grow. ⚡ Key Insight Instead of updating all cells directly, we use a 2D prefix / difference matrix technique: Update only the corners of each submatrix Convert the difference matrix into the final matrix using prefix sums Achieve O(n² + q) performance instead of O(q · n²) A neat trick that’s extremely useful for range update problems! ✅ Takeaways Difference arrays are not just for 1D — they scale beautifully to 2D Matrix prefix sums simplify many complex update operations Thinking in terms of range operations often leads to faster algorithms 💻 Tech Used Java 2D prefix sum optimization Matrix manipulation Another day, another concept mastered. On to the next challenge! 💪🔥 #coding #leetcode #java #programming #dsa #matrix #problemsolving #500DaysOfCode #Day414
To view or add a comment, sign in
-
-
🎯 Day 11 – Reverse a String Today’s DSA challenge focuses on reversing a string — a simple yet classic problem that helps strengthen your understanding of string manipulation and looping logic. Given an input string, the goal is to reverse its characters and print the reversed version. 💻 Task Description: 🔹 Take a string input from the user. 🔹 Reverse it using both methods — StringBuilder’s reverse() and a manual loop. 🔹 Display the reversed output. ✨ Perfect Alignment Moment: Posting this on 11 / 11 at 11:11 AM — it’s Day 11, Nov 11, and 11:11 — pure synchronization of effort, energy, and intention 💫 🧿 💡 Key Learning: Sometimes, even the simplest reversals can reveal new clarity — in logic and in life. 🧠 Concepts Used: Strings StringBuilder Loops ⏱ Time Complexity: O(n) 💾 Space Complexity: O(n) 📘 Every problem I solve adds one more line to my growth story — consistently, one day at a time. #Day11 #DSA #Java #KeepLearning #IntelliJ #Nov11 #11_11Arc
To view or add a comment, sign in
-
-
🚀 Day 6 of Improving Problem-Solving Today, I solved LeetCode 27: Remove Element, which at first looked like an easy problem but required careful thinking to arrive at an optimal in-place solution. 🧩 Problem Statement: Given an array nums and a value val, remove all occurrences of val in-place and return the number of elements not equal to val. ⚙️ Approach Used: Two Pointers Technique To solve this efficiently, I applied the two-pointer approach, which helps modify arrays in place without extra space. 🔹 Logic Explained: Use two pointers, i and j. j scans each element, while i tracks the position where the next valid (non-val) element should go. If nums[j] != val, assign nums[i] = nums[j] and increment both i and j. This way, all valid elements are shifted to the front, and duplicates or unwanted values are removed efficiently. 💡 This problem helped me strengthen my understanding of in-place algorithms and how two-pointer logic can simplify seemingly tricky problems. Each day, I’m realizing that solving problems isn’t just about getting the right answer — it’s about improving clarity, logic, and consistency. #Day6 #ProblemSolving #DSA #TwoPointers #LeetCode #Java #CodingJourney
To view or add a comment, sign in
-
-
🚀 Just solved LeetCode 30 – Substring With Concatenation of All Words. 🧩 What was the problem? Given a string and a list of words (all same length), you have to find every starting index where all the words appear together as a continuous substring, in any order. Basically a sliding-window puzzle with fixed word sizes and frequency matching. 🛠️ What was my approach? • Counted all words using a map • Used multiple sliding windows based on word length • Expanded the window word by word • If a word appeared more than needed, I moved the left pointer forward • Added the index when the window matched every word exactly The key was treating the string in equal chunks, not character by character. 📚 What I learned Working with strings becomes much easier when you break the problem into predictable pieces. Managing window boundaries is the real challenge here, and walking through tiny examples helps more than you think. #LeetCode #Java #DSA #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
-
📌 Day 4/100 - Minimum Size Subarray Sum (LeetCode 209) 🔹 Problem: Given an array of positive integers and a target value, find the minimal length of a contiguous subarray whose sum is greater than or equal to the target. If there’s no such subarray, return 0. 🔹 Approach: Used the Sliding Window technique for an optimized solution: Initialize two pointers (low, high) and a running sum. Expand the window by moving high until the sum ≥ target. Once valid, shrink the window from the left to find the smallest subarray. Keep updating the minimum length throughout. This reduced the time complexity from O(n²) (brute force) to O(n). 🔹 Key Learning: Sliding Window is ideal for problems with contiguous subarrays. Optimization often comes from adjusting the window efficiently. Each problem strengthens logical flow and pattern recognition. Another step forward in mastering DSA and problem-solving consistency! ⚡ #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingChallenge #SlidingWindow
To view or add a comment, sign in
-
-
🚀 Day 60 of My LeetCode Challenge Problem: Defanging an IP Address — LeetCode #1108 Today’s problem was a straightforward yet insightful string manipulation task. The goal was to replace every . in an IP address with [.]. 💡 Approach: Used a StringBuilder to efficiently construct the modified string: • Traversed each character in the given address. • When encountering a ., appended [.] to the builder. • For all other characters, appended them directly. • Converted the StringBuilder to a string and returned the result. This method ensures both clarity and efficiency while avoiding unnecessary string object creation. ⏱️ Time Complexity: O(n) — Single traversal of the string. 💾 Space Complexity: O(n) — New string built proportional to input length. Each day adds a small step toward mastering clean code and algorithmic thinking 💪 #LeetCode #Day60 #LeetCode1108 #Java #CodingChallenge #ProblemSolving #StringManipulation
To view or add a comment, sign in
-
-
🚀 Day 50 of My LeetCode Journey Today, I solved Reshape the Matrix. Problem in short: Given a matrix, reshape it to a new size r x c while keeping the row-traversal order intact. If it’s impossible, return the original matrix. Approach I used: First, check if total elements match (originalRows * originalCols == r * c). Use a single counter to traverse the original matrix and place elements in the new matrix. Map the counter to new matrix indices: row = count / c col = count % c Why this is clean: Simple and intuitive. No need for multiple variables for row and column. Works for any size matrix. Example: Original: 1 2 3 4 Reshaped to 1×4 → 1 2 3 4 This problem taught me how matrix manipulation can be simplified using smart indexing. #100DaysOfLeetCode #CodingJourney #ProblemSolving #DSA #Java #Matrix
To view or add a comment, sign in
-
-
💡 LeetCode 3467 – Transform Array 💡 Today, I solved LeetCode Problem #3467: Transform Array, which focuses on array manipulation and the use of conditional logic in Java — a neat problem that strengthens core programming fundamentals. ⚙️ 🧩 Problem Overview: You’re given an integer array nums. Your task is to: Replace even numbers with 0 Replace odd numbers with 1 Then, sort the transformed array in ascending order. 👉 Example: Input → nums = [4, 7, 2, 9] Output → [0, 0, 1, 1] 💡 Approach: 1️⃣ Iterate through the array. 2️⃣ Use a ternary operator to transform each element (even → 0, odd → 1). 3️⃣ Sort the array to arrange all zeros before ones. ⚙️ Complexity Analysis: ✅ Time Complexity: O(n log n) — due to sorting. ✅ Space Complexity: O(1) — in-place transformation. ✨ Key Takeaways: Practiced logical thinking and ternary operations in Java. Strengthened understanding of array transformations and sorting. Reinforced the value of writing clean, concise, and efficient code. 🌱 Reflection: Even simple transformation problems like this one sharpen the habit of thinking algorithmically. Consistency in small challenges leads to big growth in problem-solving skills. 🚀 #LeetCode #3467 #Java #ArrayManipulation #LogicBuilding #ProblemSolving #CodingJourney #DSA #CleanCode #ConsistencyIsKey
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