FastPrepReverse a String
Problems/Reverse a String

Reverse a String

AMD logoAMD● EasyINTERNONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks to reverse a string and discuss time and memory. The ASCII alphabet, empty case, bounds and return interface are authored for practice; approximate source match 95%. An exact source date is not available.

Return the characters of s in reverse order. Preserve spaces, punctuation, letter case and repeated characters. The empty string reverses to itself.

Function

reverseString(s: String) → String

Examples

Example 1

s = "AMD"return = "DMA"

Reading indices 2, 1 and 0 yields D, M and A.

Example 2

s = "a b!"return = "!b a"

The final exclamation mark becomes first, and the space is preserved.

Constraints

  • 0 <= s.length <= 2000.
  • Every character is printable ASCII with a code from 32 through 126.

More AMD problems

  • Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
  • LRU CacheONSITE INTERVIEW · Seen Oct 2026
  • Lowest Common Ancestor of a Binary TreePHONE SCREEN · Seen Oct 2026
All AMD interview questionsSee AMD hiring insights
Saved
public String reverseString(String s) {
    // Write your code here.
}
Checking account…