#include <stdio.h> int find_pattern(int *mem, int n) { // Write your pointer-based logic here int conceq_len_count =0; for (int needle_pos = 0; needle_pos < n; needle_pos++) { if( ((*(mem + needle_pos + 1)) - (*(mem + needle_pos))) == 1) { conceq_len_count++; if (conceq_len_count == 2) { return (needle_pos - 1); } } } return -1; } int main() { int n, arr[100]; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } int res = find_pattern(arr, n); printf("%d", res); return 0; }
Test Cases
Test Results
Input
8 2 4 5 6 9 11 12 14
Expected Output
1