Funcia
Tutorialstring

Reverse a String

Memory limit
256 MB
Correctness time limit
10000 ms
Solvers
0
0

Given a string s, return it reversed. s consists of English letters and digits only.

Examples

sresult
"hello""olleh"
"a""a"
"Ab12""21bA"

Example 1 — h-e-l-l-o read backwards.

Example 2 — One character stays the same.

Example 3 — Case and digits are kept; only the order changes.

This is a tutorial problem: there are no performance tests, just return the correct value.

Function signature

solution(s: string) → string

Constraints

  • 1≤1 \le length of s ≤1,000\le 1{,}000
  • s contains only English letters and digits.

Expected complexity

Time
O(N)
Space
O(N)

Examples

sExpected
"hello""olleh"
"a""a"
"Ab12""21bA"

Hint

Hint

Walk from the last character to the first, appending each to a new string. Shortcuts: s[::-1] in Python, std::reverse in C++, new StringBuilder(s).reverse().toString() in Java.

Time limits per language

LanguageEfficiency time limit
C (GCC, gnu17)200 msestimated
C++ (GCC, gnu++23)200 msderived
Python 3.131000 msderived
Java 251000 msderived
Kotlin 2.4 (JVM)1200 msestimated
C# 14 (.NET 10)1200 msestimated

Test groups

GroupWeightTestsVisibility
sample03inputs and outputs
correctness10011verdict only
Loading editor…
Log in to run or submit code.

No result yet. Run or submit your code.