divide_and_conquer.max_difference_pair

Functions

max_difference(→ tuple[int, int])

We are given an array A[1..n] of integers, n >= 1. We want to

Module Contents

divide_and_conquer.max_difference_pair.max_difference(a: list[int]) tuple[int, int]

We are given an array A[1..n] of integers, n >= 1. We want to find a pair of indices (i, j) such that 1 <= i <= j <= n and A[j] - A[i] is as large as possible.

Explanation: https://www.geeksforgeeks.org/maximum-difference-between-two-elements/

>>> max_difference([5, 11, 2, 1, 7, 9, 0, 7])
(1, 9)