59. Scan Memory for Three Consecutive Increasing Values

Back To All Submissions
Previous Submission
Next Submission

Code

#include <stdio.h>

int find_pattern(int *mem, int n) {
    // Write your pointer-based logic here
    int consecutives = 0;
    int index = 0;
    for(int i = 0; i < n; i++)
    {
        if(*(mem+i) == *(mem+i+1)-1)
        {
            consecutives += 1;
       
        }
        if (consecutives == 1) index = i;

        if(consecutives == 3) break;
    }
    if (consecutives == 0) index = -1;
    return index;
}

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;
}

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote