FastPrepSnake-Case Iterator to Camel Case

Snake-Case Iterator to Camel Case

Navan logoNavan● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Convert the lowercase snake-case string produced by an iterator to camel case.

Preserve every leading and trailing underscore. Inside the remaining text, remove each nonempty run of underscores and uppercase the first following letter. If the input contains only underscores, return it unchanged.

Function

snakeIteratorToCamel(text: String) → String

Examples

Example 1

text = "__hello__world___"return = "__helloWorld___"

Leading and trailing underscores are preserved, while the interior separator starts a new camel-case word.

Example 2

text = "___"return = "___"

An all-underscore input is unchanged.

Constraints

  • 1 <= text.length <= 200000.
  • text contains only lowercase English letters and underscores.

More Navan problems

See Navan hiring insights
public String snakeIteratorToCamel(String text) {
    // Write your code here.
}
text"__hello__world___"
expected"__helloWorld___"
Checking account…