My problem is for the ‘Practice problem-Construct N’ (Beginner DSA in python).
The ai gave me a wrong answer.
“a = N % 2 calculates the remainder of N when divided by 2.
b = N % 7 calculates the remainder of N when divided by 7.
if b % 2 == 0 or a % 7 == 0: checks if the remainder when N is divided by 7 is even, or if the remainder when N is divided by 2 is divisible by 7.
The problem with this logic is that it does not cover all possible combinations of 2’s and 7’s to form N. For example, for N = 14, your code will print “YES” (which is correct), but for N = 16, your code will also print “YES” when it is not possible to form 16 using any combination of 2’s and 7’s.”
It is clearly possible to form 16 using any combination of 2’s and 7’s. 28+70==16. In the testcase 1, 7 is multiplied by 0 and in the testcase 3, 2 is multiplied by 0.
To prove my point, just look at the solution given for the problem. If N = any number other than 1, 3 of 5, it will print “YES”. That means that 16 would indeed be a good answer and that the ai doesn’t know what it’s talking about. My code was good.