Because range 1..5 has each lamp in ON and OFF states, and it appears to be the smallest range for all 5<=N<=9
My solution is checking all A..B ranges for the 1st digit. If B-A>1, then I set it as A999999999 till B00000000. If B-A=1, then I try all ranges for the 2nd digit. It appears that no more recursion is necessary, so the answer will be minimal among all BD000000... - AC9999... where A..B covers all lamp states for the 1st digit (consider their existence too and treat zero as all-off) and 0..C together with D..9 covers all lamp states for the 2nd digit.