Sinusoidal string
1class Solution:
2 def sinusoidalString(self, s):
3 res = []
4 # peaks: loop through s from 1 to len(s) in increments of 4 and append to res
5 # middle: loop through s from 0 to len(s) in increments of 2
6 # troughs: loop through s from 3 to len(s) in increments of 4 and append to res
7 i = 1
8 while i < len(s):
9 res.append(s[i])
10 i += 4
11
12 i = 0
13 while i < len(s):
14 res.append(s[i])
15 i += 2
16
17 i = 3
18 while i < len(s):
19 res.append(s[i])
20 i += 4
21
22 return "".join(res)