From f05d888a0b621ca4e99e2b0fb6e23c097006fe41 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 28 May 2024 10:29:13 +0200 Subject: Init --- progs/a255.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 progs/a255.py (limited to 'progs/a255.py') diff --git a/progs/a255.py b/progs/a255.py new file mode 100644 index 0000000..5b44c24 --- /dev/null +++ b/progs/a255.py @@ -0,0 +1,12 @@ +def find_Min_Swaps(arr,n) : + noOfZeroes = [0] * n + count = 0 + noOfZeroes[n - 1] = 1 - arr[n - 1] + for i in range(n-2,-1,-1) : + noOfZeroes[i] = noOfZeroes[i + 1] + if (arr[i] == 0) : + noOfZeroes[i] = noOfZeroes[i] + 1 + for i in range(0,n) : + if (arr[i] == 1) : + count = count + noOfZeroes[i] + return count \ No newline at end of file -- cgit v1.2.3-18-g5258