Print Reversed Linked List

Easy

Given a Linked List, print it in reverse direction using recursion.

Note: Do not reverse the list.

Example
List: 1→3→4→7
Print: 7 4 3 1

Note: Each node should be separated by a space. Do not print new line anywhere. The main function will add the new line between tests.

Testing

Input Format

The first line contains ‘T’ denoting the number of independent test cases.

For each test case the input has two lines:

  • A number ‘n’, denoting the length of the linked list.
  • n space-separated integers denoting elements of the linked list.

Output Format

For each test case, the output has one line with space-separated integers.

Sample Input

2
4
1 3 4 7
3
4 5 6

Expected Output

7 4 3 1
6 5 4

Constraints

1 <= T <= 100

1 <= n <= 1000

1 <= element <= 1000

Editorial Link: Editorial