From aeb2ae07b349dbe44c6b6086b2775f2e51a30796 Mon Sep 17 00:00:00 2001 From: Mohit Majumdar <54443683+Mohit-majumdar@users.noreply.github.com> Date: Fri, 28 Oct 2022 23:40:22 +0530 Subject: [PATCH] Leader in array.py Hacktoberfest PR --- Python/leader in array.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Python/leader in array.py diff --git a/Python/leader in array.py b/Python/leader in array.py new file mode 100644 index 00000000..aea62aa0 --- /dev/null +++ b/Python/leader in array.py @@ -0,0 +1,18 @@ +import math + +def leaders(self, A, N): + #Code here + l = 0 + li = [] + for i in range(N-1,-1,-1): + if A[i] >= l: + li.append(A[i]) + l = A[i] + li.reverse() + return li +def main(): + arr = [4,3,6,7,8] + n = len(arr) + print(leaders(arr,n)) + +#Output - [8]