This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
9
HELP: hackerRank (bitwise and)
Post Flair (click to view more posts with a particular flair)
Post Body
I got the solution already (got it from github), but I'd like to know why this works to solve the Task
Given set S = {1,2,...N} . Find two integers from the set A, B where A < B, 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.
Solution down below
def bitwiseAnd(N, K):
return ( K-1 if ( (K-1) | K) <= N else K-2 )
Can someone explain, TIA.
Author
Account Strength
80%
Account Age
4 years
Verified Email
Yes
Verified Flair
No
Total Karma
144
Link Karma
125
Comment Karma
19
Profile updated: 4 days ago
Posts updated: 6 days ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/pythontips/...