Skip to content

Commit

Permalink
Add problems
Browse files Browse the repository at this point in the history
  • Loading branch information
SiddharthaMishra-dev committed Jan 27, 2023
1 parent 4bbfd13 commit a3963ab
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
27 changes: 27 additions & 0 deletions majorelement.py
Original file line number Diff line number Diff line change
@@ -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.
Empty file added removestring.py
Empty file.
Empty file added sort012.py
Empty file.
3 changes: 3 additions & 0 deletions stacksortrecur.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
st=[10,20,220,30,40]
st.pop()
print(st)
4 changes: 3 additions & 1 deletion trailingzeroes.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit a3963ab

Please sign in to comment.