Skip to content

Commit

Permalink
[Python] Challenge 3 (Unreviewed) (YearOfProgramming#357)
Browse files Browse the repository at this point in the history
* challenge 3 in python

* Challenge 3 in python YearOfProgramming#2 (Whoops)
  • Loading branch information
sarcodian authored and markjb95 committed Jan 12, 2017
1 parent 4ecd50c commit bebba7c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions challenge_3/python/sarcodian/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Majority Element
Premise

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.

You may assume that the array is non-empty and the majority element always exist in the array.

for example, given array = [2,2,3,7,5,7,7,7,4,7,2,7,4,5,6,7,7,8,6,7,7,8,10,12,29,30,19,10,7,7,7,7,7,7,7,7,7] your program should return 7
9 changes: 9 additions & 0 deletions challenge_3/python/sarcodian/src/challenge_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def majority(array0):
store = {}
for i in array0:
store[i] = store.get(i,0) + 1

for i in store.keys():
if store[i] > len(array0)//2:
return i
print('No majority found')

0 comments on commit bebba7c

Please sign in to comment.