Java Day 29: Bitwise AND




Given set S={1, 2, 3,..., N}. Find two integers, A and B



  1. import java.util.Scanner;
  2. public class Solution {
  3. public static void main(String[] args) {
  4. Scanner in = new Scanner(System.in);
  5. int T = in.nextInt();
  6. for (int i = 0; i < T; i++) {
  7. int N = in.nextInt();
  8. int K = in.nextInt();
  9. int max = 0;
  10. for (int j = 1; j < N; j++) {
  11. for (int k = j + 1; k <= N; k++) {
  12. int h = j & k;
  13. if (h < K && max < h) max = h;
  14. }
  15. }
  16. System.out.println(max);
  17. }
  18. }
  19. }
download android app

Popular HackerRank Java Solutions








codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube