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.
| Input | Output |
|---|---|
level | YES |
6 tests · Ctrl+Enter
Hints
Stris indexed by0..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.printdoes not take a bareBool.yes(b)printsYESorNO, 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.