Is there something I'm missing here? Kind of stumped on this problem. Hints are greatly appreciated!
Here is what my code is supposed to do:
You are given a string of letters and an array of numbers. The numbers indicate positions of letters that must be removed, in order, starting from the beginning of the array. After each removal the size of the string decreases (there is no empty space). Return the only letter left.
Example:
let str = "zbk", arr = [0, 1] str = "bk", arr = [1] str = "b", arr = [] return 'b'
Notes
- The given string will never be empty.
- The length of the array is always one less than the length of the string.
- All numbers are valid.
- There can be duplicate letters and numbers.
Here is my code:
def last_survivor(letters, coords):
list1 = list(letters)
for x in coords:
for i in list1:
if list1.index(i) == x:
list1.remove(i)
return print("".join(list1))
These function inputs work just fine and return expected output
last_survivor('abc', [1, 1])
last_survivor('kbc', [0, 1])
last_survivor('zbk', [2, 1])
last_survivor('c', [])
last_survivor("abcdef", [1,2,1,1])
This very long function input does not return the desired output, 'b'
last_survivor('foiflxtpicahhkqjswjuyhmypkrdbwnmwbrrvdycqespfvdviucjoyvskltqaqirtjqulprjjoaiagobpftywabqjdmiofpsr', [8, 59, 52, 93, 21, 40, 88, 85, 59, 10, 82, 18, 74, 59, 51, 47, 75, 49, 23, 56, 1, 33, 39, 33, 34, 44, 25, 0, 51, 25, 36, 32, 57, 10, 57, 12, 51, 55, 24, 55, 31, 49, 6, 15, 10, 48, 27, 29, 38, 30, 35, 42, 23, 32, 9, 39, 39, 36, 8, 29, 2, 33, 14, 3, 13, 25, 9, 25, 18, 10, 1, 2, 20, 8, 2, 11, 5, 7, 0, 10, 10, 8, 12, 3, 5, 1, 7, 7, 5, 1, 4, 0, 4, 0, 0, 1])