Editorial for Subarreglo MinMax
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Sea y
el valor del menor y el mayor elemento del arreglo respectivamente. Si
, entonces la respuesta es
. De lo contrario iteramos desde la primera posicion llevando
y
el último índice en que aparecieron el menor y el mayor elemento respectivamente. Mientras iteramos en el
-ésimo elemento si este es igual a
(
) entonces consideramos para la solución
(
). Finalmente imprimimos la menor de las posibilidades.
Complejidad
.
Comments