726. Replace Spaces with Underscores (Recursive)

EasyRecursionRecursion

Given a string s, return a new string where every space character (' ') has been replaced with an underscore ('_'). Characters other than spaces are left unchanged. You must perform the replacement recursively, without using a loop.

Input: A string s enclosed in double quotes.

Output: Return the resulting string wrapped in double quotes.

Examples

Example 1
Input: "hello world"
Output: "hello_world"
Explanation: Single space replaced.
Example 2
Input: "no_spaces"
Output: "no_spaces"
Explanation: No spaces to replace.
Example 3
Input: "a b c"
Output: "a_b_c"
Explanation: Two spaces replaced.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →