Skip to content

Commit

Permalink
Merge pull request #158 from drishtikundra/dk
Browse files Browse the repository at this point in the history
new solution
  • Loading branch information
Shashwat-Sahu committed Oct 18, 2021
2 parents f7424d6 + 139c217 commit cd41b7b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
26 changes: 26 additions & 0 deletions CodeChef/LongestANDsubarray/LongestANDsubarray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <bits/stdc++.h>
using namespace std;

int main()
{
int n,t,ans=0;
cin>>t;
for(int i=1;i<=t;i++)
{
cin>>n;
int a=floor(log2(n));
int b=pow(2,a);
int c=pow(2,(a-1));
if((n-b+1)>=(b-c))
{
ans=n-b+1;
}
else
{
ans=b-c;
}
cout<<ans<<endl;

}
return 0;
}
3 changes: 3 additions & 0 deletions CodeChef/LongestANDsubarray/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## problems link

https://www.codechef.com/OCT21C/problems/ANDSUBAR

0 comments on commit cd41b7b

Please sign in to comment.