diff options
Diffstat (limited to 'challenge-345/packy-anderson/python/ch-2.py')
| -rwxr-xr-x | challenge-345/packy-anderson/python/ch-2.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-345/packy-anderson/python/ch-2.py b/challenge-345/packy-anderson/python/ch-2.py new file mode 100755 index 0000000000..a9ac243d17 --- /dev/null +++ b/challenge-345/packy-anderson/python/ch-2.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +def last_visitor(ints): + seen = [] + ans = [] + x = 0 + for i in ints: + if i > 0: + seen.insert(0, i) # insert at front of @seen + else: + if x < len(seen): # if $x < len(@seen) + ans.append( seen[x] ) # append seen[x] to @ans + else: + ans.append( -1 ) # append -1 to @ans + x += 1 + return ans + +def solution(ints): + print(f'Input: @ints = ({", ".join(map(str, ints))})') + print(f'Output: ({", ".join(map(str, last_visitor(ints)))})') + +print('Example 1:') +solution([5, -1, -1]) + +print('\nExample 2:') +solution([3, 7, -1, -1, -1]) + +print('\nExample 3:') +solution([2, -1, 4, -1, -1]) + +print('\nExample 4:') +solution([10, 20, -1, 30, -1, -1]) + +print('\nExample 5:') +solution([-1, -1, 5, -1]) |
