Skip to content

Instantly share code, notes, and snippets.

@chairco
Last active November 12, 2018 07:45
Show Gist options
  • Save chairco/77d4752dc69495c132d169a190942084 to your computer and use it in GitHub Desktop.
Save chairco/77d4752dc69495c132d169a190942084 to your computer and use it in GitHub Desktop.
def solution(A):
    # write your code in Python 3.6
    points = []
    for row_idx, row in enumerate(A):
        row_max = max(row[1:-1])
        row_min = min(row[1:-1])
        for col_idx, col in enumerate(row[:-1]):
            col_max = max(list(zip(*A[1:-1]))[col_idx])
            col_min = min(list(zip(*A[1:-1]))[col_idx])
            if col == row_max and col == col_min:
                points.append((row_idx, col_idx))
            if col == row_min and col == col_max:
                points.append((row_idx, col_idx))

    return len(points)
def solution(A):
   n = 0
   for i in range(1, len(A) - 1):
       for j in range(1, len(A[0]) - 1):
           if min(A[i][j], A[i - 1][j], A[i + 1][j]) == A[i][j] and max(A[i][j], A[i][j - 1], A[i][j + 1]) == A[i][j]:
               n += 1
           elif max(A[i][j], A[i - 1][j], A[i + 1][j]) == A[i][j] and min(A[i][j], A[i][j - 1], A[i][j + 1]) == A[i][j]:
               n += 1
           elif max(A[i][j-1], A[i][j]) == A[i][j]:
               n += 1

   return n


def solution(A):
   n = 0
   for i in range(1, len(A) - 1):
       for j in range(1, len(A[0]) - 1):
           local_row = [A[i][j - 1], A[i][j], A[i][j + 1]]
           local_col = [A[i - 1][j], A[i][j], A[i + 1][j]]
           n += (min(local_row) == max(local_col) == A[j][j]) or \
                (max(local_row) == min(local_col) == A[j][i])
   return n
def solution(T):
    # write your code in Python 3.6
    length = len(T)
    winter_high, overall_high = T[0], T[0]
    winter_length = 0

    for temperature in T:
        if temperature <= winter_high : 
            winter_high = overall_high
        elif temperature > overall_high :
            overall_high = temperature

    for temperature in T :
        if temperature <= winter_high : 
            winter_length += 1

    return winter_length
  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment