A field engineer reads out digit displays from an odometer that occasionally gets reinstalled upside down, rotating its view by 180 degrees. On this seven-segment-style display, each digit rotates into another specific digit when viewed upside down: 0 rotates to 0, 1 rotates to 1, 6 rotates to 9, 8 rotates to 8, and 9 rotates to 6; every other digit (2, 3, 4, 5, or 7) has no valid rotated form and instantly disqualifies the reading. Given the digit string currently shown on the display, determine whether the display would show the exact same string of digits if it were rotated 180 degrees.
A single line containing a string s of length between 1 and 50, consisting only of the characters '0'-'9'.
Print "YES" if rotating the display 180 degrees reproduces the exact same digit string, otherwise print "NO".
Example 1
Input
69
Expected
YES
Explanation
Rotating each character gives 6->9 and 9->6, producing the character list [9,6]. Rotating the whole display also reverses left-to-right order, so the rotated string is the reverse of that list joined together: "69". This matches the original string "69" exactly, so the display reads the same upside down and the answer is YES.
Example 2
Input
962
Expected
NO
Explanation
The last character is '2', which has no valid rotated form since 2 does not appear in the rotation table (0,1,6,8,9 only). Because one character cannot be rotated at all, the display can never match its own upside-down view, so the answer is immediately NO regardless of the other digits.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →