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.
1 messages · Page 1 of 1 (latest)
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.
You forgot to post some code.
none of my code works... that's why i didn't post
If your code worked you wouldn't need to ask for help. If you ask for help with code that doesn't work, how do you suggest we find the problem if there's nothing to look at?
ok let me post one
#include <stdbool.h>
bool isRainbowArray(int arr[], int n) {
int i = 0;
int j = n - 1;
// Check if the array has an odd number of elements
if (n % 2 == 0) {
return false;
}
// Check if the first half is in strictly increasing order
for (i = 0; i < n/2; i++) {
if (arr[i] != i + 1) {
return false;
}
}
// Check if the second half is in strictly decreasing order
for (j = n - 1; j >= n/2; j--) {
if (arr[j] != n - j) {
return false;
}
}
// Check if the maximum element is 7 and it contains all the digits from 1 to 7
int count[8] = {0};
for (i = 0; i < n; i++) {
count[arr[i]]++;
}
for (i = 1; i <= 7; i++) {
if (count[i] != 1) {
return false;
}
}
return true;
}
int main() {
int t, n, i, j;
scanf("%d", &t);
for (i = 1; i <= t; i++) {
scanf("%d", &n);
int arr[n];
for (j = 0; j < n; j++) {
scanf("%d", &arr[j]);
}
if (isRainbowArray(arr, n)) {
printf("yes\n");
} else {
printf("no\n");
}
}
return 0;
}```
also i was unable to integrate all of the mandatory test cases
i just can't understand where to use them
Hmm, what specific part doesn't behave as it should?
i was hoping u could help on that part
I can't see any report on which test cases fail
There are quite a few issues with your code
What happens, if there is let's say number 9 somewhere?
Or, a case:
112345676543221
It passes your checks
umm but i did write a for loop for that int count[8] = {0}; for (i = 0; i < n; i++) { count[arr[i]]++; } for (i = 1; i <= 7; i++) { if (count[i] != 1) { return false; } }
Why is count supposed to be 1? How do you handle numbers bigger than 7? You just access array out of bounds, which is UB