Description

A sentence is a list of words separated by a single space. Given a sentence s and an integer k, return the sentence truncated to contain only the first k words.

Examples

Input:s = "Hello how are you Contestant", k = 4
Output:"Hello how are you"
Explanation:

First 4 words.

Input:s = "Programming is fun and rewarding when you practice regularly", k = 1
Output:Programming
Explanation:

When k=1, only the first word from the sentence is returned.

Input:s = "The quick brown fox jumps", k = 5
Output:The quick brown fox jumps
Explanation:

When k equals the total number of words in the sentence, the entire sentence is returned unchanged.

Constraints

  • 1 ≤ s.length ≤ 500

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!