Solved: LeetCode Problem 922 – Sort Array By Parity II 📌 Difficulty Level: Easy 💻 Language Used: Java 🧠 Topics: Arrays, Index Manipulation, Two-Pointer 🧩 Problem Overview: Rearrange the array so that elements at even indices are even numbers and elements at odd indices are odd numbers. 🎯 Key Learnings: ✅ Practiced separate pointer movement for even/odd indices ✅ Learned how to skip indices in steps of 2 for efficiency ✅ Strengthened control flow in condition-based pointer increment ✅ Designed an O(n) solution without extra space 🛠 Skills Practiced: Index Management Array Rearrangement Two-Pointer Optimization In-place Logic Building ⚡️ Problems like this sharpen thinking about index constraints and help in mastering array partitioning & arrangement patterns. #LeetCode #Java #RotateArray #ProblemSolving #Arrays #LogicBuilding #100DaysOfCode #CodeNewbie #TechCareers #WomenInTech #LearningInPublic #BuildInPublic #DeveloperJourney #CleanCode #DSA #AlgorithmPractice #CodingInterviewPrep #SoftwareDevelopment #AfrozCodes #DailyCoding #CrackTheCodingInterview #TechForAll
Solved LeetCode Problem 922: Sort Array By Parity II in Java
More Relevant Posts
-
📌 Day 16/100 - Reverse String (LeetCode 344) 🔹 Problem: Reverse a given string in-place — meaning you must modify the original array of characters without using extra space. 🔹 Approach: Used the two-pointer technique — one starting at the beginning and one at the end of the array. Swap characters at both pointers, then move them closer until they meet. Efficient, clean, and runs in linear time without additional memory allocation. 🔹 Key Learnings: In-place algorithms optimize space complexity significantly. The two-pointer pattern is a versatile tool for many array and string problems. Understanding mutable vs immutable structures in Java is crucial for memory efficiency. Sometimes, the simplest logic beats the most complex one. 🧠 “True efficiency lies in simplicity, not complexity.” #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #TwoPointers
To view or add a comment, sign in
-
-
✅ Day 57/100 — LeetCode Challenge Problem: Transpose Matrix Language: Java Today I worked on a classic matrix operation — transposing a matrix. The goal is to convert rows into columns and vice-versa. This problem reinforced my understanding of 2D arrays and index manipulation in Java. 💡 Key Idea: If matrix has dimensions m x n, the transpose will have dimensions n x m, and each element at (i, j) becomes (j, i). 📌 Approach: Calculate row & column length Create result matrix with swapped dimensions Iterate & swap positions accordingly #100DaysOfCode #LeetCode #Java #DSA #Matrix #TechJourney #CodingChallenge #SoftwareEngineering #LearningEveryday
To view or add a comment, sign in
-
-
📌 Day 12/100 - Concatenation of Array (LeetCode 1929) 🔹 Problem: Given an integer array nums, create a new array ans such that: ans[i] = nums[i] ans[i + n] = nums[i] where n is the length of nums. In short, we need to concatenate the array with itself to form a new array of size 2n. 🔹 Approach: First, determine the length n of the array. Create a new array newArray of size 2n. Loop through nums once: Assign each element twice — once at position i and once at position i + n. Finally, return the concatenated array. 🔹 Key Learning: Reinforced the concept of array indexing and iteration. Practiced efficient array manipulation in Java. Sometimes, the simplest logic is the cleanest — clarity beats complexity! 💡 Every solved problem adds a layer of confidence and consistency 💪 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #LearnByDoing
To view or add a comment, sign in
-
-
🚀#PostLog35 🧩 Problem: Frequency of the Most Frequent Element (LeetCode #1838) 🔹 Topic: Sliding Window 🔹 Language: Java Challenge was about maximizing the frequency of an element after performing at most k increment operations. The key idea was to use a sliding window combined with sorting: Sort the array to align potential targets. Expand the window while the total operations needed ≤ k. If it exceeds k, shrink the window from the left. Track the maximum frequency achievable. 💡 This approach efficiently balances elements using prefix sums and window logic — no need for nested loops or complex math tricks. ✅ Result: Accepted (Runtime: 33 ms) Another problem done — one step closer to mastering array and window patterns! #LeetCode #Java #CodingJourney #ProblemSolving #DSA
To view or add a comment, sign in
-
-
🔢 Today I worked on a classic matrix problem in Java — Diagonal Sum. The goal was simple: Calculate the sum of both the primary and secondary diagonals of a square matrix. Initially, I used a nested loop approach with O(n²) complexity. But then I optimized it to a clean O(n) solution by directly accessing diagonal indexes. While optimizing, I made an interesting mistake: ❌ I wrote if (i != matrix[i][matrix.length - 1 - i]) Here I accidentally compared an index with an element value. ✔ Correct approach: if (i != matrix.length - 1 - i) This ensures the center element in odd-sized matrices isn’t counted twice. 🧠 Key Learning: Indexes and values may look similar, but mixing them can break logic silently. Optimization is not just about speed — it’s about accuracy. #Java #leetcode #Coding #DSA #ProblemSolving #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
-
🎯 LeetCode Day 41/50 – Pascal’s Triangle Today’s challenge was about generating Pascal’s Triangle — a classic combinatorial structure where each number is the sum of the two numbers directly above it. 🔺 💡 Concepts used: Recursion to build rows step-by-step Dynamic List handling in Java Base case optimization for smaller triangles 🧩 Key insight: Each row can be constructed from the previous one by summing adjacent elements — a beautiful recursive pattern that reflects mathematical simplicity. 🕒 Runtime: 1 ms (Beats 85.89%) ⚡ 💾 Memory: 42.20 MB (Beats 26.63%) ✅ Result: 30/30 test cases passed — Accepted 🎉 #LeetCode #50DaysOfCode #Java #CodingChallenge #ProblemSolving #PascalTriangle
To view or add a comment, sign in
-
-
🔥 LeetCode Day--- 4 | “Median of Two Sorted Arrays” (Hard, Java) Today’s challenge was one of those that really test your logic, patience, and understanding of binary search. This problem wasn’t about just merging two sorted arrays — it was about thinking smarter 🧠. Instead of brute-forcing through both arrays (O(m+n)), I implemented a binary partition approach to achieve O(log(min(m, n))) efficiency 💡 What I learned today: Always choose the smaller array for binary search — it makes the partition logic simpler. Handle boundaries carefully with Integer.MIN_VALUE and Integer.MAX_VALUE. The goal is to find the perfect partition where: Left half ≤ Right half Elements are balanced across both arrays Once that’s done → median can be easily calculated! ✅ Result: Accepted | Runtime: 0 ms 🚀 Hard problem turned into a logic puzzle that was actually fun to solve! 🧩 Concepts Strengthened: Binary Search Partitioning Logic Edge Case Handling Mathematical Thinking #LeetCode #Day4 #Java #BinarySearch #ProblemSolving #CodingChallenge #DataStructures #Algorithms #CodeEveryday #DeveloperJourney #TechLearning #LeetCodeHard #CodingCommunity
To view or add a comment, sign in
-
-
#Day_28 Today’s problem was quite an interesting one — “Reach a Target Number” using minimal moves. 💡 Problem Summary: Starting from 0, on each move i, you can go either left or right by i steps. The goal is to find the minimum number of moves required to reach a given target. At first glance, it looked like a simple math problem, but the trick was to notice the parity condition — once the cumulative sum goes beyond the target, the difference (sum - target) must be even to allow flipping directions and still land exactly on target. Here’s the optimized logic I implemented in Java Key Takeaway: Sometimes, problems that look complex are just about observing patterns in numbers rather than brute force. A touch of math can simplify the entire logic! #100DaysOfCode #LeetCode #CodingChallenge #Java #ProblemSolving #DSA #LearnEveryday #CodingJourney
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