Find all the 0's and 1's index
Problem To find all the 0's index and 1's index in a given binary string.
Example-1:
Input : n = "1001" Output : [1, 2] [0, 3]
Example-2:
Input : n = "100101001" Output : [1, 2, 4, 6, 7] [0, 3, 5, 8]
Solution
n = "1001" l = [] k = [] for i in range(len(n)): if(n[i] == "0"): l.append(i) else: k.append(i) print(l,k)
Output
[1, 2] [0, 3]