The function loops over all characters in the string sentence. So that is n operations.
Than, in that loop, for every word the function reverse is called, so that function reverse needs n - <number of spaces> operations.
Where n is the length of the original string sentence.
Now, we apply the big Oh. n-<number of spaces> operations is just O(n). The other n operations is also O(n).
So we have O(n) + O(n) or in other words O(2n). Since constants are dropped from the big Oh (unless there is nothing but a constant, in that case it will be O(1)), the end result is O(n).
Theoretically yes, but the 2 doesn’t count in terms of the Big Oh, so that leaves O(n). The big Oh only gives a measure of complexity and since this algorithm is in linear time, it’s O(n).
What about reversing the word in each string? Say reversing a word is O(k). Since we look at each character in the Sentence, that would be O(N). Wouldn’t it be some equation involving O(n) and O(k)???