Guest User

Untitled

a guest
Jan 23rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. """
  2. If a sticker is the collection of
  3. the letters of "givecampusinc", return the
  4. number of stickers needed to complete an input
  5. string. "mice span" would require one sticker,
  6. "give mice span" would require 2 because
  7. the 2nd 'e' requires a new sticker. Treat it as case-insensitive.
  8. """
  9.  
  10. def how_many_sticks(sticker, letters_input):
  11. letters_input = letters_input.replace(' ', '')
  12. abcs = [chr(c) for c in range(ord('a'), ord('z') + 1)]
  13. sticker_letters_count = {letter: 0 for letter in abcs} # {'a': 0, 'b': 0, ..., 'z': 0}
  14. input_letters_count = {letter: 0 for letter in abcs}
  15. for letter in sticker:
  16. sticker_letters_count[letter.lower()] += 1
  17. for letter in letters_input:
  18. input_letters_count[letter.lower()] += 1
  19. max_stickers = 1
  20. for letter in letters_input:
  21. try:
  22. max_stickers = max(max_stickers, division_round_up(input_letters_count[letter], sticker_letters_count[
  23. letter]))
  24. except ZeroDivisionError:
  25. return -1
  26. return max_stickers
  27.  
  28.  
  29. def division_round_up(top, bottom):
  30. return top / bottom + (1 if top % bottom != 0 else 0)
  31.  
  32.  
  33. print how_many_sticks('givecampusinc', 'mice span') # 1
  34. print how_many_sticks('givecampusinc', 'give mice span') # 2
Add Comment
Please, Sign In to add comment