My issue
output isnt the same please help
My code
def partition(arr):
pivot = arr[-1]
idx = 0 # Index to keep track of elements smaller than pivot
for i in range(len(arr)):
if arr[i] < pivot:
# Swap arr[i] and arr[idx]
arr[i], arr[idx] = arr[idx], arr[i]
idx += 1
# Swap pivot element (last element) with arr[idx]
arr[idx], arr[-1] = arr[-1], arr[idx]
if __name__ == "__main__":
import sys
input = sys.stdin.read
data = input().strip().split()
n = int(data[0])
arr = list(map(int, data[1:n+1]))
partition(arr)
print(" ".join(map(str, arr)))
Learning course: Analysis and Design of Algorithms
Problem Link: Partitioning the array in Analysis and Design of Algorithms