Maximum Gain from an Earlier to a Later Element

Asked at Citadel · Coding Questions · Difficulty: Easy · Last asked Feb 6, 2026

A list of integers is given in order. Find the largest gain obtainable by picking one element and then a later (or the same) position, that is, the maximum of `values[j] - values[i]` over all `i <= j`. If no later element exceeds an earlier one, the answer is `0`.

Loading the problem…