Scan Memory for Three Consecutive Increasing Values

Code

#include <stdio.h>

int find_pattern(int *mem, int n){
    for(int i = 0; i<= (n-3); i++){
        if((*(mem+i) == (*(mem + i + 1) - 1)) && (*(mem+i) ==  (*(mem+i+2) - 2))){
            return i;
        }
    }
    return -1;
}

int main(){
    int n, arr[100]; 
    scanf("%d",&n); 
    
    for(int i = 0; i < n; i++){
        scanf("%d",&arr[i]);
    }
    
    printf("%d", find_pattern(arr,n));
    
    
    return 0;
} 

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

8 2 4 5 6 9 11 12 14

Expected Output

1