From 653f963c90ed4fa5c12cf0f98506d91359fcf6ed Mon Sep 17 00:00:00 2001 From: Varalakshmi2354 Date: Thu, 31 Oct 2024 15:41:13 +0530 Subject: [PATCH] Alternate sorting --- october_2024/GFG_POTD_31_OCT_2024.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 october_2024/GFG_POTD_31_OCT_2024.py diff --git a/october_2024/GFG_POTD_31_OCT_2024.py b/october_2024/GFG_POTD_31_OCT_2024.py new file mode 100644 index 0000000..72502b1 --- /dev/null +++ b/october_2024/GFG_POTD_31_OCT_2024.py @@ -0,0 +1,16 @@ +class Solution: + def alternateSort(self,arr): + arr.sort() + result = [] + i, j = 0, len(arr) - 1 + + while i <= j: + if i != j: + result.append(arr[j]) + result.append(arr[i]) + else: + result.append(arr[j]) + i += 1 + j -= 1 + + return result \ No newline at end of file