Edge Case 5 & 6 failing

Edge Case 5&6 are failing.
I have implemented the approach given in milestone 2.
I tried the test case in the below-mentioned ticket-
Input-
72057594037927935
Expected Output-
108086391056891903
No Number
My Output-
72057594029539327
No Number

But how exactly do I debug? How do I know where my code is failing?

https://forum.crio.do/t/failing-edge-test-case-6/12200

If you are doing all bit wise operation on 1 , the compiler usually considers that you are using an integer 1 (which is 31 bits and 1 sign bit) , so any shift operation of greater that 31 will result in a garbage value which is happening in your case.

To correct this mistake, try 1LL << bit_index instead so that the bit operation is done on a 64 bit signed number (and bit_index will always be less than it under the given constraints).

I hope this resolves your issue.

1 Like

image

Hey You have many similar functions like above.

The correct implementation would be
long long clear_bits_from_lower_end(ll n, ll num_of_bits) {
return n &= ~(( 1LL << num_of_bits) - 1);
}

Since 1 is an int your answer i think is overflowing, so change it to 1LL and try.

Tip for debugging: A lot of print statements before and after every function call.

@vivek_sengar

1 Like

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.