# Day 6: Bitwise Operators | 10 Days of JavaScript – Hacker Rank Solution

Day 6: Bitwise Operators | 10 Days of JavaScript – Hacker Rank Solution: Hey Guy’s In this post we are solving Day 6: Bitwise Operators which is a part of 10 Days of JavaScript Series.

We also provide Hackerrank solutions in CC++Java programming, and Python Programming languages so whatever your domain we will give you an answer in your field.

You can practice and submit all HackerRank problem solutions in one place. Find a solution for other domains and Sub-domain. I.e. Hacker Rank solution for HackerRank C ProgrammingHackerRank C++ ProgrammingHackerRank Java Programming, HackerRank Python ProgrammingHackerRank Linux ShellHackerRank SQL Programming, and HackerRank 10 days of Javascript.

As you already know that this site does not contain only the Hacker Rank solutions here, you can also find the solution for other problems. I.e. Web Technology,Data StructuresRDBMS ProgramsJava Programs Solutions,  Fiverr Skills Test answersGoogle Course AnswersLinkedin Assessment, and Coursera Quiz Answers.

## Objective

Today, we’re practicing bitwise operations. Check the attached tutorial for more details.

We define S to be a sequence of distinct sequential integers from 1 to n; in other words, S = {1, 2, 3, . . . , n}. We want to know the maximum bitwise AND value of any two integers, a and b (where a < b), in sequence S that is also less than a given integerk.

Complete the function in the editor so that given n and k, it returns the maximum a & b < k.

Note: The & symbol represents the bitwise AND operator.

## Input Format

The first line contains an integer, q, denoting the number of function calls.
Each of the q subsequent lines defines a dataset for a function call in the form of two space-separated integers describing the respective values of n and k.

## Constraints

• 1 <= q <= 103
• 2 <= n <= 103
• 2 <= k <= n

## Output Format

Return the maximum possible value of a & b < k for any a < b in sequence S.

Sample Input 0

3

5 2

8 5

2 2

Sample Output 0

1

4

0

Sample Input 1

2

9 2

8 3

Explanation 1

We perform the following q = 3 function calls:

1. When n = 5 and k = 2, we have the following possible a and b values in set S = {1, 2, 3, 4, 5}:The maximum of any a & b that is also k is 1, so we return 1.
2. When n = 8 and k = 5, the maximum of any a & b < k in set S = {1, 2, 3, 4, 5, 6, 7, 8} is 4 (see table above), so we return 4.
3. When n = 2 and k = 2, the maximum of any a & b < k in set S = {1, 2} is 0 (see table above), so we return 0.

Sample Output 1

1

2

Explanation 1

We perform the following q = 2 function calls:

1. When n = 9 and k = 2, the maximum of any a & b < k in set S = {1, 2, 3, 4, 5, 6, 7, 8, 9} is 1 (see table above), so we return 1.
2. When n = 8 and k = 3, the maximum of any a & b < k in set S = {1, 2, 3, 4, 5, 6, 7, 8} is 2 (see table above), so we return 2.

## Day 6: Bitwise Operators | 10 Days of JavaScript – Hacker Rank Solution

```'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});
process.stdin.on('end', _ => {
inputString = inputString.trim().split('\n').map(string => {
return string.trim();
});
main();
});
return inputString[currentLine++];
}
function getMaxLessThanK(n,k) {
var max=0;
for(let i=1;i<=n;i++) {
for(let j=i+1;j<=n;j++) {
var x = i&j;
if(x > max & x < k){
max = x;
}
}
}
return(max);
}
function main() {
for (let i = 0; i < q; i++) {
const [n, k] = readLine().split(' ').map(Number);
console.log(getMaxLessThanK(n, k));
}
}```

Disclaimer: The above Problem (Day 6: Bitwise Operators) is generated by Hackerrank but the Solution is Provided by Chase2Learn. This tutorial is only for Educational and Learning purposes. Authority if any of the queries regarding this post or website fill the following contact form thank you.

### FAQ:

10 days of javascript hackerrank
Answer: Join over 16 million developers in solving code challenges on HackerRank, one of the best ways to prepare for programming interviews. 10 Days of JavaScript

How can I learn JavaScript in 10 days?
Answer: Many free and paid courses and tutorials are available to learn JavaScript. For in-depth knowledge, you can also purchase a few good books like A Smarter Way to Learn JavaScript and Effective JavaScript: 68 Specific Ways to Harness the Power of JavaScript. However, to start working on projects, you need only a little theory and more hands-on, so we recommend you to take up tutorials and short courses that will get you onboard quickly.

Does hacker rank have JavaScript?
Answer: They might not have a specific practice tutorial for it. But you can solve any of their general problems using Javascript.

What is HackerRank JS?
Answer: The HackerRank Skills Certification Test is a standardized assessment to help developers prove their coding skills.

Finally, we are now, in the end, I just want to conclude some important message for you

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.