Iโve officially started my Top 150 LeetCode journey to strengthen my foundations in Data Structures & Algorithms.
โ Progress: 3 / 150 Problems Solved
Rather than rushing through problems, my focus is on understanding patterns, improving reasoning, and writing cleaner solutions over time.
๐งฉ Problems Solved Today
1๏ธโฃ Merge Sorted Array
Approach:
Merged elements from the second array into the first and applied sorting to maintain order.
Key Learning:
A working solution isnโt always the optimal one. This problem introduced the importance of thinking about pointer-based merging instead of relying purely on sorting.
class Solution {
public:
vector<int> merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
for(int i = m; i < m + n; i++) {
nums1[i] = nums2[i - m];
}
for(int i = 0; i < m + n - 1; i++) {
for(int j = 0; j < m + n - i - 1; j++) {
if(nums1[j] > nums1[j+1]) {
swap(nums1[j], nums1[j+1]);
}
}
}
return nums1;
}
};
2๏ธโฃ Remove Element
Approach:
Used a write pointer (idx) to overwrite unwanted values in-place.
Key Learning:
Many array problems reduce to maintaining a correct write index rather than deleting elements.
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
int idx = 0;
for(int i = 0; i < nums.size(); i++){
if(nums[i] != val){
nums[idx++] = nums[i];
}
}
return idx;
}
};
3๏ธโฃ Remove Duplicates from Sorted Array
Approach:
Compared current element with the previous one and stored only unique values using a pointer.
Key Learning:
Sorted arrays unlock simpler logic โ recognizing structure in input data is powerful.
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
if(nums.empty()) return 0;
int idx = 1;
for(int i = 1; i < nums.size(); i++) {
if(nums[i] != nums[i-1]) {
nums[idx++] = nums[i];
}
}
return idx;
}
};
๐ง Reflection
Early DSA problems look simple, but they build essential habits:
- thinking in-place,
- minimizing extra memory,
- recognizing reusable patterns.
This challenge isnโt about speed โ itโs about consistent improvement.
๐ Next Target: Top 150 continuesโฆ
If youโre also working on DSA or building consistency in problem solving, letโs grow together.
๐ GitHub โ https://github.com/CodeWithDeeksh
๐ฆ X โ https://x.com/deekshithax
One problem at a time. Consistency over intensity.
Top comments (0)