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)
{
    int *ptr = mem;
    int index = 0;

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