From a3963ab8f5e3c8ede08b952fd0c53d52e0c5af89 Mon Sep 17 00:00:00 2001 From: SiddharthaMishra-dev Date: Fri, 27 Jan 2023 13:26:28 +0530 Subject: [PATCH] Add problems --- majorelement.py | 27 +++++++++++++++++++++++++++ removestring.py | 0 sort012.py | 0 stacksortrecur.py | 3 +++ trailingzeroes.py | 4 +++- 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 majorelement.py create mode 100644 removestring.py create mode 100644 sort012.py create mode 100644 stacksortrecur.py diff --git a/majorelement.py b/majorelement.py new file mode 100644 index 0000000..14b91cc --- /dev/null +++ b/majorelement.py @@ -0,0 +1,27 @@ +# Moore's voting Algorithm for major element in an Array + +arr=[1,2,3,4,5] +major=arr[0] +count=1 +n=len(arr) +for i in range(1,n): + if major==arr[i]: + count+=1 + else: + count-=1 + if count ==0: + major=arr[i] + +c=0 +for i in range(n): + if major==arr[i]: + c+=1 + +if c>n//2: + print(major) +else: + print("No answer") + + +# This algorithm works on the concept element priority in the array. +# if next index number is same as preceeding number then importance of the element increases otherwise decreases. \ No newline at end of file diff --git a/removestring.py b/removestring.py new file mode 100644 index 0000000..e69de29 diff --git a/sort012.py b/sort012.py new file mode 100644 index 0000000..e69de29 diff --git a/stacksortrecur.py b/stacksortrecur.py new file mode 100644 index 0000000..984b335 --- /dev/null +++ b/stacksortrecur.py @@ -0,0 +1,3 @@ +st=[10,20,220,30,40] +st.pop() +print(st) \ No newline at end of file diff --git a/trailingzeroes.py b/trailingzeroes.py index 22cf767..b67e939 100644 --- a/trailingzeroes.py +++ b/trailingzeroes.py @@ -1,6 +1,8 @@ n=int(input()) res=0 -for i in range(5,n,*5): +i=5 +while i<=n: res+=n/i + i=i*5 print(res)