Skip to Content

Mirror word

Level A. Teaches Str, indexing and yes().

You are given one word of lowercase letters, at most 10⁵ long. Print YES if it reads the same backwards, otherwise NO.

Input: the word. Output: YES or NO.

InputOutput
levelYES
6 tests · Ctrl+Enter
Hints
  • Str is indexed by 0..s.len, one byte per character, in O(1).
  • (0..n).all(k => ...) asks a question of every index; there is no flag variable to forget to reset.
  • print does not take a bare Bool. yes(b) prints YES or NO, the spelling most judges want.
  • A loop that sets a flag and breaks is what the search_loop lint flags, and if ok: "YES" else: "NO" is what bool_ternary_print flags.