problem :: https://hack.codingblocks.com/app/dcb/143
my code :: https://ide.codingblocks.com/s/196713
i am getting tle for 2 test cases.
please help me optimising my code.
problem :: https://hack.codingblocks.com/app/dcb/143
my code :: https://ide.codingblocks.com/s/196713
i am getting tle for 2 test cases.
please help me optimising my code.
@vsinghal277 i don’t get why you are taking two inputs n1 and n2 for each test case .just take a number input and run your logic. check here i have updated your code a little bit (https://ide.codingblocks.com/s/196755)
the code u sent is of finding setbits of a given decimal no…BUT MY QUESTION IS DIFFERENT .PLEASE CHECK TODAY’S CODEBYTE. THIS QUESTION IS OF HACKERBLOCKS TODAY’S CODEBYTE
@vsinghal277 sorry my bad.
for this problem you are just using brute force hence will give you TLE.there comes many optimzed techniques to calculate set bit from 1 to n,here i am using one of those technique and 2’s complementary to handle negative numbers.check my code you will understand (https://ide.codingblocks.com/s/197021)
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.