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 index = 0;
    int* it = mem;
    while((it + 3) <= (mem + (n - 1)))
    {
        if(((*(it + 1) - *(it)) == 1) && ((*(it + 2) - *(it + 1)) == 1)) return index;
        it++;
        index++;
    }

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

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote