#!/bin/ruby # your code goes here n = gets.strip.to_i a = gets.strip a = a.split(' ').map(&:to_i) a = a.sort i = a.length - 1 min_diff = (a[-1] - a[0]).abs # should be max diff so good place to start, also deals with case where length of a is 1 while i > 0 diff = (a[i] - a[i-1]).abs min_diff = diff if diff < min_diff i -= 1 end p min_diff