@@ -0,0 +1,717 @@
+import java.io.*;%0Aimport java.util.*;%0Aimport java.text.*;%0Aimport java.math.*;%0Aimport java.util.regex.*;%0A%0Apublic class Solution %7B%0A%0A  // naive approach O(32) ~ O(1)%0A  public static long flipBits(long value) %7B%0A    int i = 31;%0A    while (i %3E= 0) %7B%0A      value %5E= 1L %3C%3C i;%0A      i--;%0A    %7D%0A    return value;%0A  %7D%0A%0A  public static long flipBitsUpdated(long value) %7B%0A    // create mask of all ones for 32 MSB%0A    // this runs faster than naive approach%0A    long mask = ~0L %3E%3E%3E 32;%0A    return value %5E mask;%0A  %7D%0A%0A  public static void main(String%5B%5D args) %7B%0A    Scanner in = new Scanner(System.in);%0A    int t = in.nextInt();%0A    for (int i = 0; i %3C t; i++) %7B%0A      System.out.println(flipBitsUpdated(in.nextLong()));%0A    %7D%0A  %7D%0A%7D%0A

add flipping bits solution