Algorithms and Data Structures · Middle · Question 71 of 75

What is the time complexity of str.split("").sort().join("") for a string of length n?

Explanation

Splitting and joining are O(n), but sorting the characters is O(n log n), which dominates. For short words it doesn't matter; for long strings counting characters is O(n).

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 71

Test yourself

Take the Algorithms and Data Structures · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz