Tutorialstring
Reverse a String
- Memory limit
- 256 MB
- Correctness time limit
- 10000 ms
- Solvers
- 0
Given a string s, return it reversed. s consists of English letters and digits only.
Examples
| s | result |
|---|---|
"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
- length of
s scontains only English letters and digits.
Expected complexity
- Time
- O(N)
- Space
- O(N)
Examples
| s | Expected |
|---|---|
"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
| Language | Efficiency time limit | |
|---|---|---|
| C (GCC, gnu17) | 200 ms | estimated |
| C++ (GCC, gnu++23) | 200 ms | derived |
| Python 3.13 | 1000 ms | derived |
| Java 25 | 1000 ms | derived |
| Kotlin 2.4 (JVM) | 1200 ms | estimated |
| C# 14 (.NET 10) | 1200 ms | estimated |
Test groups
| Group | Weight | Tests | Visibility |
|---|---|---|---|
| sample | 0 | 3 | inputs and outputs |
| correctness | 100 | 11 | verdict only |