FastPrepCrop a Notification at Whole-Word Boundaries
Problems/Crop a Notification at Whole-Word Boundaries

Crop a Notification at Whole-Word Boundaries

Marshall Wace logoMarshall Wace● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Marshall Wace online assessment. The report leaves out the function declaration and the input limits. Here, there is a clear minimum limit of three characters, and words use English letters. Our version is about 95% the same as the reported question.

A message contains words separated by one space. Return a notification containing at most K characters.

  • If the entire message fits, return it unchanged.
  • Otherwise remove whole words from its end. Keep as many complete words as possible from the beginning and append ...: one space followed by three ASCII dots.
  • If no word can remain, return ... with no preceding space.

The dots and their separating space count toward the limit. Never split a word or leave a trailing space.

Function

solution(message: String, K: int) → String

Examples

Example 1

message = "And now here is my secret"K = 15return = "And now ..."

A longer prefix would exceed the limit after including the space and dots.

Example 2

message = "alpha beta"K = 10return = "alpha beta"

The complete message fits exactly, so no ellipsis is added.

Example 3

message = "longword x"K = 7return = "..."

The first word plus a space and three dots would exceed seven characters.

Constraints

  • For this exercise, assume 1 <= message.length <= 100000 and 3 <= K <= 100000.
  • For this exercise, assume words contain English letters, with exactly one space between words and no leading or trailing spaces.

More Marshall Wace Online Assessment questions

  • Count Letters with Ordered Lowercase and Uppercase OccurrencesOA · Seen Oct 2025
  • Maximum Trailing Zeros on a Path with at Most One TurnOA · Seen Oct 2025
  • Shortest Subarray Covering an Integer RangeOA · Seen Oct 2025
  • Maximum Events in a 60-Second WindowOA · Seen Aug 2025
  • Successful Logins from Multiple CountriesOA · Seen Aug 2025
  • Maximize Remaining Item Types After Clearing Consecutive ShelvesOA · Seen Nov 2024
  • Shortest String After Erasing Equal PairsOA · Seen Nov 2024
  • Count Distinct Tags in a Fixed-Radius Circle (Practice Reconstruction)OA · Seen Apr 2024
  • Generate Unique Company Email AddressesOA · Seen Apr 2024
  • Reconstruct a Two-Row Binary MatrixOA · Seen Apr 2024

Similar questions at other companies

  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • First Non-Repeating CharacterAmazon · OA · ONSITE INTERVIEW
  • Maximum Ones After K OperationsGoldman Sachs · OAGoldman Sachs interview questions
  • Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
  • Find Words That Can Be Formed by CharactersTabaPay · OA
  • Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
  • Count Palindrome Addition ChoicesThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
  • Count Palindrome Addition ChoicesHudson River Trading · OAHudson River Trading interview questions
  • Count Phrases Formed by Anagram ReplacementWells Fargo · OAWells Fargo interview questions
  • Count Substrings With Identical CharactersVirtu Financial · OAVirtu Financial interview questions

Interview reports that mention this question

  • Marshall Wace Coding Tests: 11 Experiences (Part 2 of 3)
  • Marshall Wace Quant and Coding OA: 19 Experiences (Part 1 of 3)

Marshall Wace interview experiences

  • Marshall Wace Older Quant Tests: 5 Experiences (Part 3 of 3)
All Marshall Wace interview questionsSee Marshall Wace hiring insights
Saved
class Solution {
    public String solution(String message, int K) {
        // Write your solution here.
    }
}
Checking account…