aboutsummaryrefslogtreecommitdiff
path: root/challenge-345/packy-anderson/python/ch-2.py
blob: a9ac243d17d563111e23acc18a68b34fbbfac4ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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])