💡 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
Solved LeetCode 3467: Transform Array in Java
More Relevant Posts
-
📌 Day 18/100 - Valid Palindrome (LeetCode 125) 🔹 Problem: Determine whether a string reads the same forward and backward, ignoring case and non-alphanumeric characters. 🔹 Approach: Implemented a two-pointer technique. Skipped all non-alphanumeric characters. Compared characters from both ends in lowercase. Returned true if all matched, otherwise false. 🔹 Key Learning: Two-pointer method keeps logic clean and efficient. Character handling is key when data isn’t uniform. Time complexity: O(n), Space complexity: O(1). Sometimes, solving elegantly is better than solving fast. ✨ #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney
To view or add a comment, sign in
-
-
🔹 Day 40 – LeetCode Practice Problem: Find Greatest Common Divisor of Array (LeetCode #1979) 📌 Problem Statement: Given an integer array nums, find the greatest common divisor (GCD) of the smallest and largest numbers in the array. ✅ My Approach (Java): 1. Find the minimum and maximum elements in the array. 2. Starting from the smaller number and going downwards, check for the highest integer that divides both min and max. 3. Return that integer as the GCD. 📊 Complexity: Time Complexity: O(n + min(a, b)) Space Complexity: O(1) ⚡ Submission Results: Accepted ✅ Runtime: 0 ms (Beats 100%) 🚀 Memory: 43.41 MB (Beats 41.55%) 💡 Reflection: This problem shows how basic math logic and loop optimization can lead to extremely efficient solutions. A simple and powerful way to practice number theory in coding! #LeetCode #ProblemSolving #Java #DSA #CodingPractice #Learning
To view or add a comment, sign in
-
-
🔥 Day 17 of My LeetCode Journey — Problem #377: Combination Sum IV (Dynamic Programming) Today’s focus was on Dynamic Programming — specifically tackling problems where order matters in combinations. 🧩 Problem Summary: Given an array of distinct integers and a target integer, the task was to compute the number of possible combinations that sum up to the target. 💡 Approach & Key Insights: Utilized bottom-up Dynamic Programming (1D array approach) to efficiently compute results. Base case: dp[0] = 1, representing one way to reach a sum of zero. Iteratively built combinations where the sequence order impacts the outcome, differentiating it from subset problems. ⚙️ Algorithmic Complexity: Time: O(n × target) Space: O(target) 📈 Performance Outcome: ✅ Accepted Solution ⚡ Runtime: 1 ms (Beats 67.14% of Java submissions) 💾 Memory: 41.19 MB Each day’s challenge continues to refine my analytical reasoning and problem-solving efficiency, bringing me one step closer to mastering algorithmic design patterns in Java. #LeetCode #Java #DynamicProgramming #CodingJourney #ProblemSolving #TechLearning #SoftwareEngineering
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 74 of LeetCode Medium/Hard Edition Today’s challenge was “Minimum Falling Path Sum II” — a dynamic programming problem that blends recursion, memoization, and row-wise optimization ⚡💡 📦 Problem: You're given an n × n integer matrix. A falling path selects exactly one element from each row, and the restriction is: No two consecutive elements may be chosen from the same column. Return the minimum possible sum of such a falling path. 🔗 Problem Link: https://lnkd.in/gbKyfbqs ✅ My Submission: https://lnkd.in/gtg_qzW8 💡 Thought Process: This problem extends the classic minimum falling path by enforcing a non-zero shift, meaning the chosen column must change at every row. To solve this efficiently, we can use Dynamic Programming with memoization, where: dp[r][c] represents the minimum falling path sum starting from grid[r][c]. From each cell, we explore all columns in the next row except the same one. Memoization prevents recomputing overlapping subproblems. A further optimization uses the idea of tracking: the minimum and second minimum values from the previous row So when transitioning: If the current column ≠ min-index → pick the global minimum Else → pick the second minimum This eliminates the O(n³) brute force and reduces complexity to O(n²). 🎯 Base Cases: The last row directly contributes its cell value: dp[n-1][c] = grid[n-1][c] Transition occurs upward row by row. Memoized states avoid repeated work. ⚙️ Complexity: ⏱ Time: O(n²) with optimized DP 💾 Space: O(n²) with memo / O(n) with rolling array 🧩 Key Learnings: Strengthened understanding of state transitions with constraints. Practiced converting a brute DFS idea into an efficient DP + memo solution. Learned how tracking min & second-min values avoids nested loops. Solidified recursion-to-DP thinking for grid-based problems. #LeetCodeMediumHardEdition #100DaysChallenge #DynamicProgramming #Java #DSA #ProblemSolving #LearnEveryday
To view or add a comment, sign in
-
-
💡 LeetCode 1929 – Concatenation of Array 💡 Today, I solved LeetCode Problem #1929: Concatenation of Array, a simple yet satisfying problem that tests your understanding of array manipulation and indexing in Java. ⚙️📊 🧩 Problem Overview: You’re given an integer array nums. Your task is to create a new array ans such that ans = nums + nums (i.e., concatenate the array with itself). 👉 Example: Input → nums = [1,2,1] Output → [1,2,1,1,2,1] 💡 Approach: 1️⃣ Find the length n of the given array. 2️⃣ Create a new array of size 2 * n. 3️⃣ Loop through nums once — place each element both at index i and index n + i. 4️⃣ Return the resulting array. ⚙️ Complexity Analysis: ✅ Time Complexity: O(n) — Single traversal of the array. ✅ Space Complexity: O(n) — For the concatenated array. ✨ Key Takeaways: Practiced index manipulation and array construction. Reinforced the importance of efficient iteration. A great warm-up problem that strengthens logical thinking and array fundamentals. 🌱 Reflection: Even the simplest problems build the foundation for solving more complex ones. Every bit of consistent practice helps in mastering problem-solving and clean coding habits. 🚀 #LeetCode #1929 #Java #ArrayManipulation #DSA #CodingJourney #CleanCode #ProblemSolving #AlgorithmicThinking #ConsistencyIsKey
To view or add a comment, sign in
-
-
💻 Day 51 of #LeetCode100DaysChallenge Solved LeetCode 13: Roman to Integer — a problem that tests mapping, iteration, and conditional logic. 🧩 Problem: Given a Roman numeral, convert it to an integer. Roman numerals use symbols I, V, X, L, C, D, and M. Normally, symbols are added from largest to smallest. However, in six cases (IV, IX, XL, XC, CD, CM), subtraction is applied. 💡 Approach — Mapping & Iteration: 1️⃣ Create a map of Roman symbols to integer values. 2️⃣ Iterate through the string: Add the value if the current symbol is greater than or equal to the next. Subtract the value if the current symbol is smaller than the next. 3️⃣ Sum all values to get the final integer. ⚙️ Complexity: Time: O(N) Space: O(1) ✨ Key Takeaways: ✅ Practiced mapping and iteration. ✅ Handled edge cases with subtraction logic. ✅ Reinforced sequential decision-making in string processing. #LeetCode #100DaysOfCode #Java #Mapping #Iteration #ConditionalLogic #DSA #CodingJourney #WomenInTech #RomanToInteger
To view or add a comment, sign in
-
-
🚀 Day 73 of #100DaysOfCode Today I solved LeetCode 3346 – Maximum Frequency of an Element After Performing Operations I 🧩 This problem was all about logical range manipulation — figuring out how many elements could be converted into the same number when each element can be modified by ±k, but with a limited number of allowed operations. At first, it felt similar to the “most frequent element” sliding window problem, but the twist here was controlling how many elements can be changed, not just the total cost. After a few failed attempts (and a battle with edge cases 😅), I finally implemented a correct solution using the difference array + prefix sum approach. 💡 Key Takeaways: Think in terms of ranges, not just differences. Prefix-sum (difference map) logic is incredibly powerful for interval counting. Always recheck constraints — “number of operations” vs “total cost” makes a huge difference! Here’s a snippet from my final Java solution: int achievable = Math.min(running, same + numOperations); ans = Math.max(ans, achievable); It’s small details like these that make problem-solving such a rewarding process 💪 #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #DSA #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 392 of #500DaysOfCode Today I solved LeetCode 661: Image Smoother 🖼️ This problem was all about applying a 3x3 smoothing filter on an image (represented as a 2D matrix). For each pixel, we calculate the average value of the surrounding pixels — considering only the valid neighbors — and take the floor of the result. It’s a great exercise for mastering matrix traversal and boundary condition handling in Java! 💡 🔍 Key Learnings: How to navigate a 2D grid using directional arrays. Handling edge cells carefully (like corners and borders). Efficiently applying averaging filters using nested loops. 🧠 Example: Input: [[100,200,100],[200,50,200],[100,200,100]] Output: [[137,141,137],[141,138,141],[137,141,137]] 💻 Language: Java 🔹 Difficulty: Easy Every problem like this strengthens my fundamentals in array manipulation and spatial algorithms — one step closer to writing cleaner, more efficient code. #Day392 #LeetCode #Java #CodingChallenge #100DaysOfCode #500DaysOfCode #ProblemSolving #SoftwareEngineering #MatrixAlgorithms
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
-
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