# 246 Strobogrammatic Number

A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).

Write a function to determine if a number is strobogrammatic. The number is represented as a string.

For example, the numbers "69", "88", and "818" are all strobogrammatic.

**The Idea:** Good reference: <https://oeis.org/A000787>. A number is strobogrammatic if it is pair wise palindromic. That is, looking at the vertical reflection of the number, 8 maps with 8, 9 maps with 6, 1 maps with 1, ... etc.

**Complexity:** O(n) time and O(1) space

```python
class Solution:
    def isStrobogrammatic(self, num):
        """
        :type num: str
        :rtype: bool
        """
        if not num:
            return False

        sym_pair = {'8': '8', '6': '9', '9': '6', '1': '1', '0': '0'}
        left = 0
        right = len(num) - 1

        while left <= right:
            l_val = num[left]
            r_val = num[right]
            if l_val not in sym_pair or r_val not in sym_pair:
                return False
            elif sym_pair[l_val] != r_val or sym_pair[r_val] != l_val:
                return False
            left += 1
            right -= 1

        return True


obj = Solution()
print(obj.isStrobogrammatic('69'))
for sn in [str(num) for num in [0, 1, 8, 11, 69, 88, 96, 101, 111, 181, 609, 619, 689, 808, 818, 23, 9199]]:
    print(obj.isStrobogrammatic(sn))
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://maksimdan.gitbook.io/interview-practice-problems/leetcode_sessions/246-strobogrammatic-number.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
