#Check to see if a array is a rainbow array

4 messages · Page 1 of 1 (latest)

compact oak
#

int isRainbowArray(int A[], int N) {
    if (N % 2 == 0) {
        return 0; // If the array size is even, it can't be a rainbow array
    }else {
        int middle = N / 2;
        for (int i = 0; i <= middle; i++) {
            if (A[i] != A[N - 1 - i] || A[i] < 1 || A[i] > 7) {
                return 0; // If elements don't match the rainbow pattern, it's not a rainbow array
            }
        }
    }
    return 1;
}

int main() {
    int numTestCases;
    scanf("%d", &numTestCases);

    for (int t = 0; t < numTestCases; t++) {
        int N;
        scanf("%d", &N);

        int A[N];

        // Input the array elements
        for (int i = 0; i < N; i++) {
            scanf("%d", &A[i]);
        }

        // Check if it's a rainbow array
        if (isRainbowArray(A, N)) {
            printf("yes\n");
        } else {
            printf("no\n");
        }
    }

    return 0;
}```
opaque flintBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

void portal
#

If the array size is even, it can't be a rainbow array

Is 1 2 3 3 2 1 not a rainbow array?

compact oak
#

@void portal no its not