We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 29: Bitwise AND
Day 29: Bitwise AND
+ 0 comments *python***
def bitwiseAnd(N, K): max_val = 0
for A in range(1, N + 1): for B in range(A + 1, N + 1): current_val = A & B if current_val < K and current_val > max_val: max_val = current_val return max_val
+ 0 comments c++ solution int bitwiseAnd(int N, int K) { int max_val = 0;
for (int A = 1; A <= N; A++) { for (int B = A + 1; B <= N; B++) { int current_val = A & B; if (current_val < K && current_val > max_val) { max_val = current_val; } } } return max_val;
}
+ 0 comments C++ Solution:
int result = 0; int biggest = 0; for(int i = 1; i < N; i++) { for(int j = i+1; j <= N; j++) { result = i & j; if(result > biggest && result < K) biggest = result; } } return biggest;
+ 0 comments def bitwiseAnd(N, K): list=[] for i in range(1,N+1): for j in range(i+1,N+1): P=i&j if P
+ 0 comments python
def bitwiseAnd(N, K): list=[] for i in range(1,N+1): for j in range(i+1,N+1): P=i&j if P
Load more conversations
Sort 416 Discussions, By:
Please Login in order to post a comment