All problems
1070EasyHash TableTwo PointersString

Does the Reading Survive a Half Turn

Tracked in this browser only
Write code

Trains the technique from

LeetCode 246Strobogrammatic Number

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A reading is given as the string num, made only of digits.

Turning the whole reading upside down turns each digit in place and reverses their order. Only some digits survive the turn: 0, 1 and 8 turn into themselves, while 6 and 9 turn into each other. Every other digit becomes unreadable.

Return whether the reading looks exactly the same after being turned upside down.

Examples

Example 1

Input
num = "1961"
Output
true

The outer ones turn into each other, and the nine and six in the middle swap into each other, so the turned reading matches the original.

Example 2

Input
num = "25"
Output
false

The two has no turned form at all, so the reading cannot survive.

Example 3

Input
num = "0"
Output
true

A single zero turns into itself, so the reading is unchanged.

Constraints

  • 1 <= num.length <= 50
  • The reading is made of digits only.
  • The reading has no leading zero unless it is the single digit zero.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def is_strobogrammatic(num: str) -> bool:
Java
public boolean isStrobogrammatic(String num)
September 7
Apply