From f05d888a0b621ca4e99e2b0fb6e23c097006fe41 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 28 May 2024 10:29:13 +0200 Subject: Init --- progs/a686.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 progs/a686.py (limited to 'progs/a686.py') diff --git a/progs/a686.py b/progs/a686.py new file mode 100644 index 0000000..960f706 --- /dev/null +++ b/progs/a686.py @@ -0,0 +1,22 @@ +def right_rotate(arr, n, out_of_place, cur): + temp = arr[cur] + for i in range(cur, out_of_place, -1): + arr[i] = arr[i - 1] + arr[out_of_place] = temp + return arr +def re_arrange(arr, n): + out_of_place = -1 + for index in range(n): + if (out_of_place >= 0): + if ((arr[index] >= 0 and arr[out_of_place] < 0) or + (arr[index] < 0 and arr[out_of_place] >= 0)): + arr = right_rotate(arr, n, out_of_place, index) + if (index-out_of_place > 2): + out_of_place += 2 + else: + out_of_place = - 1 + if (out_of_place == -1): + if ((arr[index] >= 0 and index % 2 == 0) or + (arr[index] < 0 and index % 2 == 1)): + out_of_place = index + return arr \ No newline at end of file -- cgit v1.2.3-18-g5258