Menu
Coddy logo textTech

Find K

Lesson 16 of 17 in Coddy's Bit Manipulation course.

challenge icon

Challenge

Medium

Given an integer <strong>n</strong>, find the maximum value of integer k such that the following condition holds:

  • <strong>n & (n−1) & (n−2) & (n−3) & ... (k) = 0</strong>

where & denotes the bitwise AND operation.

Try it yourself

#include <cmath>
using namespace std;

int FindK(int n) {
    // Write code here
}

All lessons in Bit Manipulation