708. Print All Elements of Array Recursively

EasyRecursionRecursion

Given an integer array nums, return a single string containing all elements of nums in order, separated by single spaces. You must build the string recursively without using any loops. For an empty input the result is an empty string (this case will not occur in tests; n >= 1).

Input: An integer array nums.

Output: Return a string of integers separated by single spaces.

Examples

Example 1
Input: [1,2,3,4,5]
Output: 1 2 3 4 5
Explanation: Each element printed in order, separated by spaces.
Example 2
Input: [7]
Output: 7
Explanation: Single element, no separator needed.
Example 3
Input: [-1,-2,-3]
Output: -1 -2 -3
Explanation: Negatives included as-is.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →