val to 0, cnt to 0, and pow to 1. These variables will keep track of the current value of the binary number, the count of '1's included, and the current power of 2, respectively.s from right to left.val (multiplied by pow) would not exceed k.cnt, add pow to val, and double pow.pow without changing cnt or val.cnt to it to get the result.