SQUADVOICE Hiring | Off-Campus OA (2023) | Truncate Sentence Problem

Question · Posted Jun 2026

Q1: Truncate Sentence Problem Statement A sentence is a sequence of words separated by a single space. Given a sentence s and an integer k, return the sentence after keeping only the first k words. Example Input s = "Hello how are you Contestant" k = 4 Output Hello how are you Explanation The first four words are: Hello how are you Hence, the truncated sentence is: Hello how are you Constraints 1 <= k <= number of words <= ...

The full answer & interview discussion are available to premium members.

Log in Create a free account