Back/DFS: Reverse Words

DFS: Reverse Words

EasyLevel: 10Topic: Graphs
XP Reward:+50 XPCoin Reward:+5 Coins

You are given a sequence of words. Return the same words in reverse order, separated by a single space.

This problem is part of Graphs practice and is designed to strengthen the DFS pattern.

Input Format

  • The first line contains an integer n, the number of words.
  • The remaining input contains n lowercase words.

Output Format

Return one line containing the words in reverse order.

Example 1

Input:

5
code logic nexo alpha code

Output:

code alpha nexo logic code

Explanation:

  • The original order is code -> logic -> nexo -> alpha -> code.
  • After reversing, the order becomes code alpha nexo logic code.

Constraints

  • 1 <= n <= 10^5
  • Each word contains only lowercase English letters.

Return Requirement

Implement the starter function for this Easy problem. Read from the raw input string and return only the required answer, with no labels or debug text.

Judge Behavior

Run Code checks the visible sample cases. Submit checks those samples plus additional hidden cases that follow the same input format and constraints.

Loading editor...
Input
5
code logic nexo alpha code
Expected Output
code alpha nexo logic code