Skip to content

Instantly share code, notes, and snippets.

@abinhho
Created July 31, 2020 14:53
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 abinhho/51ede91bafc9a1ba5f0169f0b3c3485a to your computer and use it in GitHub Desktop.
Save abinhho/51ede91bafc9a1ba5f0169f0b3c3485a to your computer and use it in GitHub Desktop.
def count_numbers(sorted_list, less_than):
count = 0
length = len(sorted_list)
if not length:
return 0
if length == 1:
return count + 1 if sorted_list[0] < less_than else count
elif sorted_list[-1] < less_than:
return count + length
elif sorted_list[0] > less_than:
return count
half = length//2
return count_numbers(sorted_list[:half], less_than) + count_numbers(sorted_list[half:], less_than)
sorted_list = [1, 2, 3, 3, 3, 4, 4 ,5, 5, 5, 5, 7]
print(count_numbers(sorted_list, 5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment