Suffix Chain
Return the string made by writing s, then s without its first character, then s without its first two characters, and so on, ending with the last character of s on its own. The empty string gives the empty string.
Slicing inside a loop works, but notice the recursion: the chain of s is s followed by the chain of s[1:].
For example, "abc" gives "abc" + "bc" + "c", which is "abcbcc".
Example 1
s "abc"
returns "abcbcc"
The pieces are abc, bc and c, written one after another.
Example 2
s "a"
returns "a"
A single character is its own chain.
Constraints
0 <= len(s) <= 10shas lowercase letters only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Recursion problems
- Wheels in the RowBeginner
- Deep ReverseEasy
- Depth-Weighted SumEasy
- Digit Product StepsEasy
- Downhill SpillEasy
- Every ArrangementEasy
- Every Riffle ShuffleEasy
- Flatten CompletelyEasy