I don't think your solution is linear. Split and Join functions have time complexity too. A true O(n) solution would iterate over the string directly(only once) and make changes on the fly. Looping through the given string and capitalizing any character that has a space before can be a O(n) I think.
I don't think your solution is linear. Split and Join functions have time complexity too. A true O(n) solution would iterate over the string directly(only once) and make changes on the fly. Looping through the given string and capitalizing any character that has a space before can be a O(n) I think.
Well, given split and join are also O(n) then you would have some complexity like
3n + x
which still is O(n) since you would remove all constants.