Without Using Space
Without Using Space
If a sorting algorithm with an auxiliary space is used, such as Mergesort or Timsort, the space
complexity would be O(n+m)
2. Use two pointers to compare and merge elements:
Start with the first element of each array and compare them. Move the smaller element to the merged
array and increment the pointer for that array. Repeat this process until all elements are merged. If any
elements are remaining in either array, append them to the merged array.
TC: O(n+m) SC: O(n+m).
WITHOUT USING SPACE
2-sum
3-sum
4-sum
Chocolate Distribution Problem