Princess Kammo and her marriage

0

0 votes
Medium
Problem

Kammo, the princess of Maccharpur is extremely fond of mathematicians, so she decided to marry two mathematicians. n people with distinct intelligence levels as C1, C2,....,Cn came to marry her. She made them stand in a line. Now, she wants to marry the persons with minimum positive difference in their intelligence levels (Ci-Cj) such that i < j and i != n. Find out those two persons and output the desired difference.

Constraints:
1 < n <= 2*10^5
1 <= Ci <= 10^6
All intelligent levels are distinct
Valid answer exists always.

Input Format:
First line contains an integer n denoting the number of persons.
Second line contains the n space separated long integers with the respective intelligence levels as C1, C2,....,Cn.

Sample input 1
3
4 10 3
Ans: 1
Kammo will marry the person with intelligence C1 = 4 and C3 = 3.

Sample input 2
5
18 7 8 2 5
Ans: 2
Kammo will marry the person with intelligence C2 = 7 and C5 = 5.

Time Limit: 0.5
Memory Limit: 256
Source Limit:
Editor Image

?