Yeah. Once you do a series of solutions using Dynamic Programming, you'll get a feel for it!
Thanks for the clear explanation Derk-Jan Karrenbeld!
Here is my implementation in Python:
#!/usr/bin/env python3 import sys if __name__ == '__main__': adapters = list(sorted(map(int, sys.stdin.read().strip().split('\n')))) adapters = [0] + adapters valid_arrangements = [1] * len(adapters) for index in range(1, len(adapters)): valid_arrangements[index] = sum( valid_arrangements[src_index] for src_index in range(max(0, index - 3), index) if adapters[index] - adapters[src_index] <= 3 ) print(valid_arrangements[-1])
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Yeah. Once you do a series of solutions using Dynamic Programming, you'll get a feel for it!
Thanks for the clear explanation Derk-Jan Karrenbeld!
Here is my implementation in Python: