"""
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

P   A   H   N
A P L S I I G
Y   I   R
And then read line by line: "PAHNAPLSIIGYIR"

Write the code that will take a string and make this conversion given a number of rows:
"""
from typing import Dict

class Solution:
    def convert(self, s: str, numRows: int) -> str:
        if numRows == 1:
            return s
        results = {i: "" for i in range(0, numRows)}
        marker = 0
        reset = 2 * numRows - 2
        row_map = get_row_map(numRows, reset)
        for i, char in enumerate(s):
            row = row_map[i % reset]
            results[row] += char
            marker += 1
        return "".join([x for k, x in results.items()])


def get_row_map(numRows, reset: int) -> Dict[int, int]:
    row_map = {i: i for i in range(0, numRows)}
    for i in range(numRows, reset):
        row_map[i] = reset - i
    return row_map
"""
Implement atoi which converts a string to an integer.

The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible,
 and interprets them as a numerical value.

The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.

If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.

If no valid conversion could be performed, a zero value is returned.

Note:

Only the space character ' ' is considered as whitespace character.
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. If the numerical value is out of the range of representable values, INT_MAX (231 − 1) or INT_MIN (−231) is returned.
"""

DIGIT_MAP = {str(i): i for i in range(0, 10)}
MAX_INT = 2**31

class Solution:
    def myAtoi(self, s: str) -> int:
        s = s.lstrip(" ")
        if len(s) == 0:
            return 0
        sign = 1
        results = []
        if s[0] == "-":
            sign = -1
            s = s[1:]
        elif s[0] == "+":
            s = s[1:]
        for char in s:
            if char not in DIGIT_MAP:
                break
            results.append(DIGIT_MAP[char])

        res = 0
        power = 1
        for i in range(len(results) - 1, -1, -1):
            res += results[i]*power
            power *= 10
        if res > MAX_INT:
            if sign == -1:
                return MAX_INT * sign
            return MAX_INT - 1
        return res * sign
Add working solutiuon