X1662: insertUnderscore

Description

Given a string, compute recursively a new string where all the adjacent chars are now separated by an underscore ("_"). So given "hello", return "h_e_l_l_o".

Constraints

  • You cannot use the following methods from the String class: indexOf, lastIndexOf, contains, endsWith, startsWith, matches, replace, nor replaceAll.

Documentation

Examples:

insertUnderscore("abc") -> "a_b_c"
insertUnderscore("a") -> "a"

Your Answer:

Feedback

Your feedback will appear here when you check your answer.