Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
944 B
1
Indexable
Never
test_cases = [
    ([1,2,3,4, 0], False),
    ([3,1,4,2], True),
    ([-1,3,2,0], True),
]

import math


def find_pattern(arry):
    """Find pattern."""
    if len(arry) < 3:
        return False
    # for each uphile find a downhile.
    # uphiles = [(idx, upper_val), ...]
    # [1, 2, 3, 4]
    uphiles = dict()
    min_i = math.inf
    for i in range(len(arry) - 1):
        left, right = arry[i], arry[i + 1]
        min_i = min([min_i, left])
        # process downhile immediately.
        if uphiles:
            pass
        if left < right:
            uphiles.update({i + 1: (min_i, right)})

    for idx, tupl in uphiles.items():
        lower_val, upper_val = tupl
        for item in arry[idx + 1:]:
            if lower_val < item < upper_val:
                return True
    return False


if __name__ == "__main__":
    for arry, jdg in test_cases:
        assert find_pattern(arry) is jdg