FunctionRacerProblemsRace

Suffix Chain

BeginnerRecursionPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Recursion problems