Hackerrank “30 Days of Code” Çözümleri – Day 29: Bitwise AND

Hackerrank’in 30 Days of Code içerisinde bulunan “Day 29: Bitwise AND” sorusunun açıklaması ve çözümü. Bu soruda bitwise and (&) operatörünün nasıl çalıştığına bir örnek ile göz attık.

Hackerrank 30 Days of Code Çözümleri – Day 29: Bitwise AND: https://www.hackerrank.com/challenges/30-bitwise-and/problem

► Problem açıklaması:


Welcome to the last day! Today, we’re discussing bitwise operations. Check out the Tutorial tab for learning materials and an instructional video!


Given set S = {1, 2, 3, .. N}. Find two integers, A and B (where A less B), from set S such that the value of A&B is the maximum possible and also less than a given integer, K. In this case, & represents the bitwise AND operator.

Function Description

Complete the bitwiseAnd function in the editor below.

bitwiseAnd has the following paramter(s):

– int N: the maximum integer to consider

– int K: the limit of the result, inclusive


– int: the maximum value of A&B within the limit.

Input Format

The first line contains an integer, T, the number of test cases. Each of the T subsequent lines defines a test case as 2 space-separated integers, N and K, respectively.

Sample Input

STDIN Function

—– ——–

3 T = 3

5 2 N = 5, K = 2

8 5 N = 8, K = 5

2 2 N = 8, K = 5

Sample Output




Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.