Skip to content

Instantly share code, notes, and snippets.

@zilder
Last active October 19, 2016 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zilder/d45982f065218dfe53c378cc2d493184 to your computer and use it in GitHub Desktop.
Save zilder/d45982f065218dfe53c378cc2d493184 to your computer and use it in GitHub Desktop.
class NumberCounter(object):
def __init__(self, value, counter):
self.value = value
self.counter = counter
def second_min_count(values):
mins = [NumberCounter(None, 0), NumberCounter(None, 0)]
for value in values:
for pos, min in enumerate(mins):
if value < min.value or min.value is None:
mins.insert(pos, NumberCounter(value, 1))
break
elif value == min.value:
mins[pos].counter += 1
break
mins = mins[:2]
return mins[1].counter
print second_min_count( [1, 5, 3, 8, 7, 3, 1, 6] ) # >>> 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment