Step 1: Compare last element of Array1 (20) with first element of Array2 (2), swap because 20 > 2
Array1: [1, 5, 9, 10, 15, 2]
Array2: [20, 3, 8, 13]
Why: We want smaller elements in Array1 and larger in Array2 to maintain sorted order.
Step 2: Sort Array2 after swap: Array2 becomes [3, 8, 13, 20]
Array1: [1, 5, 9, 10, 15, 2]
Array2: [3, 8, 13, 20]
Why: Sorting Array2 keeps it sorted after the swap.
Step 3: Sort Array1 after swap: Array1 becomes [1, 2, 5, 9, 10, 15]
Array1: [1, 2, 5, 9, 10, 15]
Array2: [3, 8, 13, 20]
Why: Sorting Array1 keeps it sorted after the swap.
Step 4: Compare last element of Array1 (15) with first element of Array2 (3), swap because 15 > 3
Array1: [1, 2, 5, 9, 10, 3]
Array2: [15, 8, 13, 20]
Why: Continue swapping to ensure smaller elements are in Array1.
Step 5: Sort Array2: [8, 13, 15, 20]
Array1: [1, 2, 5, 9, 10, 3]
Array2: [8, 13, 15, 20]
Why: Keep Array2 sorted after swap.
Step 6: Sort Array1: [1, 2, 3, 5, 9, 10]
Array1: [1, 2, 3, 5, 9, 10]
Array2: [8, 13, 15, 20]
Why: Keep Array1 sorted after swap.
Step 7: Compare last element of Array1 (10) with first element of Array2 (8), swap because 10 > 8
Array1: [1, 2, 3, 5, 9, 8]
Array2: [10, 13, 15, 20]
Why: Swap to maintain sorted order.
Step 8: Sort Array2 remains [10, 13, 15, 20], no swap needed now
Array1: [1, 2, 3, 5, 9, 8]
Array2: [10, 13, 15, 20]
Why: Arrays are now fully sorted without extra space.
Step 9: Sort Array1: [1, 2, 3, 5, 8, 9]
Array1: [1, 2, 3, 5, 8, 9]
Array2: [10, 13, 15, 20]
Why: Keep Array1 sorted after swap.
Result: Array1: [1, 2, 3, 5, 8, 9]
Array2: [10, 13, 15, 20]