DEV Community

Discussion on: Challenge-- Capitalize each word in a string

Collapse
 
nazmulpcc profile image
Nazmul Alam

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.

Collapse
 
neradev profile image
Moritz Schramm

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.