727. Concatenate N Copies of a String

EasyRecursionRecursion

Given a string s and a non-negative integer n, return the string obtained by concatenating n copies of s. If n is 0 or s is empty, return an empty string. You must implement the concatenation recursively.

Input: A string s and a non-negative integer n, formatted as "s", n.

Output: Return the concatenated string wrapped in double quotes.

Examples

Example 1
Input: "ab", 3
Output: "ababab"
Explanation: 'ab' repeated three times.
Example 2
Input: "hi", 0
Output: ""
Explanation: Zero copies -> empty string.
Example 3
Input: "x", 5
Output: "xxxxx"
Explanation: Five copies of 'x'.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →