Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Solution {
- def main(args: Array[String]) {
- val sc = new java.util.Scanner (System.in);
- var n = sc.nextInt();
- var A = new Array[Int](n);
- for(A_i <- 0 to n-1) {
- A(A_i) = sc.nextInt();
- }
- val result = calculateDistances(A)
- if(result.size>0)
- print(calculateDistances(A).min)
- else
- print("-1")
- }
- def calculateDistances(data:Array[Int]):Array[Int] = {
- val result = for(i <- 0 until data.size ; j <- i+1 until data.size; if data(i) == data (j)) yield (j-i)
- result.toArray
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement