Coding Challenge #11

Coding Challenge Series / Technical Interview Series

A function you create is provided as a parameter a string of arbitrary length. This string has special characteristics though — once a character is read, it is zeroed out and is then read-only.

You may access the string’s individual characters either as an array or a function (whichever your programming language supports, for example string[#] or string.getChar(#)); no other built-in string functions may be used.

The function you create must do the following:

  • Find the longest segment delimited by a character, provided as a second parameter to the function
  • The start of the string and the end of the string should be treated as if they are the delimiter character.
  • Return the longest segment as a new string.
  • Your function may not make a copy of the entire string (only if it matches the long segment).
  • If two segments are the same length, return the last one found.

One Comment

  1. I was not aware that If two segments have similar length I should return the last segment found. Thanks for this tip

Comments are closed.