Skip to content

Instantly share code, notes, and snippets.

@Ch-sriram
Created October 29, 2020 20:45
Show Gist options
  • Save Ch-sriram/cb5e6b35ae6e82fe31daab2cbf662270 to your computer and use it in GitHub Desktop.
Save Ch-sriram/cb5e6b35ae6e82fe31daab2cbf662270 to your computer and use it in GitHub Desktop.
Number is Sparse or Not [TC: O(logN); SC: O(1)]
// Problem Link: https://practice.geeksforgeeks.org/problems/number-is-sparse-or-not-1587115620/1/
bool isSparse(int n) {
for(int i = 0; i < 32; ++i)
if(((n >> i) & 3) == 3)
return false;
return true;
}
@Ch-sriram
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment