Problem was with ( ) == a[i]
I also made the same mistake
its the brackets that’s giving you ac. (a[i] & a[j]) == a[i]
== has higher preference than & operator
That’s why you got WA in first code.
got it. operator precedence, my bad sorry !
So what’s your question exactly ?
If you are asking that why second one got AC then its because (i<j) was given in question and you need to put the operands of bitwise &, in round brackets.
This is the reason you should turn on compiler warnings. I wrote the first code, and got a warning.
My Geany Compiler Flags are:
Compile (F8):
g++ -std=c++17 -Wshadow -Wall -o "%e" "%f" -O2 -Wno-unused-result
Build (F9):
g++ -std=c++17 -Wshadow -Wall -o "%e" "%f" -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG
‘==’ is done first and then ‘&’. The problem is just with the brackets.
Yes but it worked for the samples. That is why I submitted the code in the first place.
In sample all the number were same in the array
Then can you explain why it worked for the sample test case?
Just generate some test cases and check which ones have different output on the codes.
So it was intentionally done
in the first sample all the numbers were the same and in the second one, you don’t get to the point of comparison
I guess so
I think first loop should be till n-1 and the brackets .
Do the dry run you will understand .
Ps: we are checking for pairs hence why should we check for last element ?
No, j
has to be less than n
I said first loop brother
I know that. If i is n-1, j will be n but it should be less than n it won’t work.