微软OA 2019

类似 rotated array.


这题注意5的情况,比如956,应该返回9565,不是9556

image

Q1
image

Q2

Q3 - Given a string and an integer. Break the string in such a way that:

  • The resulting string should not contain parts of a word.
  • The resulting string should not contain spaces.
  • If the size of K is greater than length of given string then return the given string as it is.

Example 1:
Input: wordWrap(“Codility We test coders”, 14)
Output: Codility We
Explaination: If we split until 14 characters then output will be Codility We te but since te is part of a word so ignore that. Also notice we ignore the space after We and test in our output.

Example 2:
Input: wordWrap(“The quick brown fox jumps over the lazy dog”, 39)
Output: The quick brown fox jumps over the lazy

Example 3:
Input: wordWrap(“Why not”, 39)
Output: Why not

Explaination: Since the size of K is greater than the length of given string so we return the string as it is.