Q1 Four and two wheels
Q2 Given a encoded string and decode it
Input:
"mnes--ya-----mi"
*Output:
"my name is"
Explaination:
[[m, n, e, s, -],
[-, y, a, -, - ],
[-, -, -, m, i]]
Read from upleft corner diagnoally. Each row is left filled with "-" (row 0 with 0 "-", row 1 with 1, etc...)
Space is also displayed as "-".
My solution:
def solution(encodedString, numberofRows):
alphacnt = sum(x.isalpha() for x in encodedString)
cols = len(encodedString) // numberofRows
res = []
for i in range(0, len(encodedString), cols):
res.append(encodedString[i:i+cols])
i = j = 0
changerow = 0
cnt = 0
ans = ""
while cnt < alphacnt:
if res[i][j].isalpha():
ans += res[i][j]
cnt += 1
else:
ans += " "
i += 1
j += 1
if i == numberofRows:
changerow += 1
i = 0
j = changerow
return ans