Tutorialstringtwo-pointers
Palindrome Word
- Memory limit
- 256 MB
- Correctness time limit
- 10000 ms
- Solvers
- 0
Given a string s of lowercase English letters, return true if it reads the same forwards and backwards (a
palindrome), otherwise false. "level" and "noon" are palindromes; "hello" is not.
Examples
| s | result |
|---|---|
"level" | true |
"hello" | false |
"a" | true |
Example 1 — Backwards it is still level.
Example 2 — Reversed it becomes olleh.
Example 3 — A single character is always a palindrome.
This is a tutorial problem: there are no performance tests, just return the correct value.
Function signature
solution(s: string) → bool
Constraints
- length of
s scontains only lowercase English letters.
Expected complexity
- Time
- O(N)
- Space
- O(1)
Examples
| s | Expected |
|---|---|
"level" | true |
"hello" | false |
"a" | true |
Hint
Hint
Either reverse the string and compare it with the original, or compare s[i] with s[j] starting from both ends
(i = 0, j = length - 1) and moving inwards; any mismatch means false.
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 |