Bulb Switcher II LeetCode solution in Java
1class Solution {2public int flipLights(int n, int presses) {3// 1, 2 -> 34// 1, 3 -> 25// 2, 3 -> 16// all on, all off, even on, odd on, 3k+1 on, 3k+0+2 on, 3k+1 w/ 2, 3k+1 w/ 37if (n == 2 && presses == 1) return 3;8if (presses == 1)9return Math.min(101 << Math.min(4, n),114); // i chose 4 arbitarily, just has to be big enough to cover small number and less than12// 3113if (presses == 2) return Math.min(1 << Math.min(4, n), 7);14if (presses >= 3) return Math.min(1 << Math.min(4, n), 8);15return 1;16}17}