VOOZH about

URL: https://www.geeksforgeeks.org/interview-experiences/tcs-coding-practice-question-reverse-a-string/

⇱ TCS Coding Practice Question | Reverse a String - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

TCS Coding Practice Question | Reverse a String

Last Updated : 11 Jul, 2025

Given a string, the task is to reverse this String using Command Line Arguments. Examples:

Input: Geeks
Output: skeeG
Input: GeeksForGeeks
Output: skeeGroFskeeG

👁 Image
Approach 1: Using another String to store the reverse

  • Since the string is entered as Command line Argument, there is no need for a dedicated input line
  • Extract the input string from the command line argument
  • Create a String to store the resultant reversed string, say reversedString
  • Traverse through this String character by character using loop, in reverse order
  • Now append each character into the resultant reversedString
  • This is the required reversed string

Program:

Output:

In Python


👁 Screenshot-2023-07-19-165133

Approach 2: Without using another String to store the reverse

  • Since the string is entered as Command line Argument, there is no need for a dedicated input line
  • Extract the input string from the command line argument
  • Traverse through this String character by character using loop till half the length of the string
  • Swap the characters from one end with the characters from the other end
  • This is the required reversed string

Program:

Output:

Comment