diff --git a/submissions/AyushTiwari/MoveZero/Screenshot (3).png b/submissions/AyushTiwari/MoveZero/Screenshot (3).png new file mode 100644 index 0000000..0b59b01 Binary files /dev/null and b/submissions/AyushTiwari/MoveZero/Screenshot (3).png differ diff --git a/submissions/AyushTiwari/MoveZero/solution2.py b/submissions/AyushTiwari/MoveZero/solution2.py new file mode 100644 index 0000000..37d450a --- /dev/null +++ b/submissions/AyushTiwari/MoveZero/solution2.py @@ -0,0 +1,15 @@ +class Solution: + def moveZeroes(self, nums): + # Pointer to place the next non-zero element + insert_pos = 0 + + # First pass: move all non-zero elements to the front + for i in range(len(nums)): + if nums[i] != 0: + nums[insert_pos] = nums[i] + insert_pos += 1 + + # Second pass: fill the remaining positions with zeroes + while insert_pos < len(nums): + nums[insert_pos] = 0 + insert_pos += 1 diff --git a/submissions/AyushTiwari/PlusOne/Screenshot (1).png b/submissions/AyushTiwari/PlusOne/Screenshot (1).png new file mode 100644 index 0000000..72708b1 Binary files /dev/null and b/submissions/AyushTiwari/PlusOne/Screenshot (1).png differ diff --git a/submissions/AyushTiwari/PlusOne/solution.py b/submissions/AyushTiwari/PlusOne/solution.py new file mode 100644 index 0000000..7a4a932 --- /dev/null +++ b/submissions/AyushTiwari/PlusOne/solution.py @@ -0,0 +1,21 @@ +class Solution: + def merge(self, nums1, m, nums2, n): + i = m - 1 # Pointer for last valid element in nums1 + j = n - 1 # Pointer for last element in nums2 + k = m + n - 1 # Pointer for the end of nums1 + + # Merge both arrays starting from the end + while i >= 0 and j >= 0: + if nums1[i] > nums2[j]: + nums1[k] = nums1[i] + i -= 1 + else: + nums1[k] = nums2[j] + j -= 1 + k -= 1 + + # Copy any remaining elements from nums2 (if any) + while j >= 0: + nums1[k] = nums2[j] + j -= 1 + k -= 1