• + 1 comment

    This is my solution in python3

    import math
    import os
    import random
    import re
    import sys
    from typing import List
    
    def optimal(array: List):
        returned_values_left: list[int] = []
        returned_values_right: list[int] = []
        for index, item in enumerate(array):
            if index == 0:
                returned_values_left.append(0)
            else:
                if item < array[index - 1]:
                    returned_values_left.append(index)
                else:
                    returned_values_left.append(0)
    
            if index == len(array)-1:
                returned_values_right.append(0)
            else:
                if item < array[index + 1]:
                    returned_values_right.append(index + 2)
                else:
                    returned_values_right.append(0)
        return [returned_values_left,returned_values_right]
        
    #
    # Complete the 'solve' function below.
    #
    # The function is expected to return an INTEGER.
    # The function accepts INTEGER_ARRAY arr as parameter.
    #
    
    def solve(arr):
        # Write your code here
        value = sys.maxsize * -1
        [left,right] = optimal(arr)
    
        for position in range(len(arr)):
            new_value = left[position] * right[position]
            if new_value > value:
                value = new_value
    
        return value