FunctionRacerProblemsRace

Truncate Sentence

BeginnerStringsPython, JavaScript, TypeScript, Java, C++

Words in s are separated by single spaces. Return a string holding only the first k words of s, separated by single spaces.

Example 1

s "Hello how are you"
k 2
returns "Hello how"

The first two words are Hello how.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems