MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

Codeforces_problems/Remove Smallest/Solution.cpp:9–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7using namespace std;
8
9int main()
10{
11 long long int t;
12 scanf("%lld", &t);
13
14 while(t--)
15 {
16 long long int n , i , flag = 0;
17 scanf("%lld", &n);
18 long long int a[n];
19
20 for( i = 0 ; i < n ; ++i)
21 {
22 scanf("%lld", &a[i]);
23 }
24
25 sort(a , a + n); // sorting array in ascending order to ensure minimum difference of the consecutive elements
26
27 for(i = 0 ; i < n - 1 ; ++i)
28 {
29 if(a[i + 1] - a[i] <= 1) // checking if the difference between two consecutive elements of array is less than equal to one
30
31 continue; // the loop executes from the beginning if the condition in 'if' is satisfied
32
33 else
34 {
35 flag++; // increment the counter to validate that the condition has become false
36 break; // end for loop as soon as the condition becomes false
37 }
38 }
39
40 if(flag == 1) // check if the counter has incremented after the condition became false
41 printf("NO\n"); // print 'NO' in that case
42 else
43 printf("YES\n"); // else print 'YES'
44
45 }
46
47 return 0;
48}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected