Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
int const N = 1e2 + 1;
int n, a[N];
int main() {
scanf("%d", &n);
for(int i = 0; i < n; ++i)
scanf("%d", a + i);
int mn = 1e9 + 1, k, l;
for(int i = 0; i < n; ++i)
if(abs(a[i] - a[(i + 1) % n]) < mn) {
mn = abs(a[i] - a[(i + 1) % n]);
k = i;
l = (i + 1) % n;
}
printf("%d %d\n", k + 1, l + 1);
return 0;
}
Copy The Code &
Try With Live Editor
Input
5
10 12 13 15 10
10 12 13 15 10
Output
5 1
Demonstration
Codeforcess Solution Reconnaissance 2 ,A. Reconnaissance 2 C,C++, Java, Js and Python ,A. Reconnaissance 2,Codeforcess Solution