fork download
  1. def arrange_guest_arrival_order(arrival_pattern):
  2. num = 1
  3. counter = 0
  4. res = []
  5. i = 0
  6. while (i < len(arrival_pattern)):
  7. if arrival_pattern[i] == "I":
  8. res.append(num)
  9. num+=1
  10. i+=1
  11. else:
  12. counter = 1
  13. j = i+1
  14. while (j < len(arrival_pattern)):
  15. if (arrival_pattern[j] == "D"):
  16. counter+=1
  17. j+=1
  18. else:
  19. break
  20. num += counter
  21. i += counter+1
  22. for k in range(counter+1):
  23. res.append(num-k)
  24. counter -= 1
  25. return res
  26. print(arrange_guest_arrival_order("IIIDIDDD"))
Success #stdin #stdout 0.08s 14196KB
stdin
Standard input is empty
stdout
[1, 2, 3, 5, 4, 8, 7, 6, 5]