Funcia
Tutorialstringtwo-pointers

Palindrome Word

Memory limit
256 MB
Correctness time limit
10000 ms
Solvers
0
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

sresult
"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

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

Expected complexity

Time
O(N)
Space
O(1)

Examples

sExpected
"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

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.