The code is about determining "two distinct elements" in an integer array where the index of these two aren't the same and doing the bit-wise operation between them gives "1".
"The time to execute this following program is 500ms." But since I got a nested for loop here, I'm getting TLE. How can I modify this code to meet the requirements?
Note that this is the only way I know how to check something in the array and I can only code in C language. The code is as follows:
#include <stdio.h>
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n, count = 0;
scanf("%d", &n);
int num[n];
for (int i = 0; i < n; i++)
scanf("%d", &num[i]);
for (int i = 0; i < n - 1; i++)
{
for (int j = i + 1; j < n; j++)
{
if ((num[i] ^ num[j]) == 1)
count = 1;
}
}
count == 1 ? printf("Yes\n") : printf("No\n");
}
return 0;
}