what is the problem with this code?
Last question in bitmasking
Hey Hritam, actually the code by Prateek Sir has few bugs:
- j++ should be outside for loop(as you ignore elements whose corresponding bit is 0)
- an edge case (n=1) gives segmentation fault.
- for n<=17, you may directly generate all subset sums and check if it lies within given range.
Try rectifying these
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.