Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions submissions/AyushTiwari/MoveZero/solution2.py
Original file line number Diff line number Diff line change
@@ -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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions submissions/AyushTiwari/PlusOne/solution.py
Original file line number Diff line number Diff line change
@@ -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