Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Introductory Problems/Chessboard and Queens (1624)/anubhav.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <bits/stdc++.h>
int column[8]={0}, d1[15]={0},d2[15]={0};
char c[8][8];
using namespace std;
int ans;
void rec(int q)
{
if(!(q-8))
ans++;
else{
for(int i=0;i<8;i++)
{
if(!( column[i] or d1[q+ i] or d2[7-q+i]) and c[q][i]=='.')
{
column[i] = d1[q+ i] = d2[7-q+i]=1;
rec(q+1);
column[i] = d1[q+ i] = d2[7-q+i]=0;
}
}
}
return;
}
int main() {
for(int i=0;i<8;i++)
for(int j=0;j<8;j++)
cin>>c[i][j];
rec(0);
cout<<ans;
return 0;
}
9 changes: 9 additions & 0 deletions Introductory Problems/Palindrome Reorder (1755)/anubhav.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
s,a,o,c,l=input(),'','',0,[0]*27
for i in s:
l[ord(i)-ord('A')+1]+=1
for i in range(1,27):
a+=chr(i+ord('A')-1)*(l[i]//2)
if l[i]%2==1:o,c=chr(i+65-1),c+1
if(c>1):break
if c>1:print("NO SOLUTION")
else:print(a+o+a[::-1])
36 changes: 36 additions & 0 deletions Sorting and Searching/Maximum Subarray Sum (1643)/anubhav.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <bits/stdc++.h>
#define loop(i,n) for(long long i=0;i<n;++i)
using namespace std;
int main()
{
long long n;
scanf("%lld",&n);
long long a[n];
bool pos=0;
loop(i,n)
{
scanf("%lld",a+i);
if(a[i]>0)
pos=1;
}
long long max_end=0, max_so_far=0;
if(pos)
{
loop(i,n)
{
max_end+=a[i];
if(max_end<0)
max_end=0;
if(max_so_far<max_end)
max_so_far=max_end;
}
}
else{
max_so_far=-1000000000;
loop(i,n)
if(max_so_far<a[i])
max_so_far=a[i];
}
printf("%lld",max_so_far);
return 0;
}
24 changes: 24 additions & 0 deletions Sorting and Searching/Playlist (1141)/anubhav.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <bits/stdc++.h>
#define loop(i,n) for(int i=0;i<n;++i)
using namespace std;
int main()
{
int n,len=0;
scanf("%d",&n);
int a[n];
map <int, int > song;
loop(i,n)
{
scanf("%d",a+i);
song[ a[i] ]=0;
}
int j=0,i=0;
loop(i,n)
{
j=max(j,song[a[i]]);
len=max(len,i-j+1);
song[a[i]]=i+1;
}
printf("%d",len);
return 0;
}
44 changes: 44 additions & 0 deletions Sorting and Searching/Room Allocation (1164)/anubhav.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <bits/stdc++.h>
#define loop(i,n) for(int i=0;i<n;++i)
using namespace std;
int main()
{
int n,a,d;
scanf("%d",&n);
multiset <pair < int , int > >arrival;
multiset < pair < int, int > >depart;
vector < pair < int, int > > sch;
map<int, int > room;
multiset < pair < int, int > >::iterator itr;
loop(i,n)
{
scanf("%d %d",&a,&d);
sch.push_back(make_pair(a,d));
arrival.insert(make_pair(a,i));
depart.insert(make_pair(d,i));
}
int room_num=0;
while(arrival.size())
{
++room_num;
int arr,ind,dept;
itr=arrival.begin();
while(true)
{
arr=(*itr).first;
ind=(*itr).second;

arrival.erase(itr);

room[ind]=room_num;
dept=sch[ind].second;
depart.erase(depart.find(make_pair(dept,ind)));

itr=arrival.upper_bound(make_pair(dept,10000000));
if(itr==arrival.end())
break;
}
}
cout<<room_num<<endl;
loop(i, sch.size() )
cout<<room[i]<<' ';