We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

many compilers are optimized for tail-recursion which makes such functions less inefficient than one would normally expect them to be. For example, the tailRec keyword in Scala.

## String Mingling

You are viewing a single comment's thread. Return to all comments →

Hello! I wonder why is this solution is better than mine:

It is tail recursive function, list concatenation has linear complexity

many compilers are optimized for tail-recursion which makes such functions less inefficient than one would normally expect them to be. For example, the tailRec keyword in Scala.

@serhii_nesteruk,

`::`

has constant complexity, while`++`

is linear.In your code you are applying

`++`

ntimes. First on the list of length 1, then 2, then 3, and so on. So overall complexity will bethanks for the explanation!