Question DSA-STR-0045
MediumWhat is the output of this code?
s = "aaabccdddd"
out, i = "", 0
while i < len(s):
j = i
while j < len(s) and s[j] == s[i]:
j += 1
out += s[i] + str(j - i)
i = j
print(out)
- A.
a3b1c2d4
- B.
3a1b2c4d
- C.
a3bc2d4
- D.
abcd
Sign up free to see the answer and a step-by-step explanation.