Check if a Number is a Twisted Prime

Given an integer n, reverse its decimal digits. Return true when both n and its reversed value are prime. Otherwise, return false. A single-digit prime is…

Given an integer `n`, reverse its decimal digits. Return `true` when both `n` and its reversed value are prime. Otherwise, return `false`. A single-digit prime is twisted prime because reversing it produces the same prime value.

- `2 ≤ n ≤ 10^6` - `n` is always a positive integer.

Example 1: input n = 13; output true. Both 13 and its reverse 31 are prime.

Example 2: input n = 23; output false. Although 23 is prime, its reverse 32 is not prime.

Example 3: input n = 11; output true. Reversing the prime 11 produces the same prime value.

Category: Math. Topic: math. Difficulty: Easy. Patterns: math.