HOTEL-practice problem...what is my mistake??

#include
using namespace std;

int arrive[1000];
int leave[1000];
int main()
{

int test,n,max,count;
cin>>test;
while(test--)
{   max=0;
    cin>>n;
    for(int i=0;i<n;++i)
    {

               cin>>arrive[i];
    }
     for(int i=0;i<n;++i)
    {

               cin>>leave[i];
    }
    for(int i=0;i<n;++i)
    {
            count=0;
           for(int j=0;j<n;++j)
           {
                    if (!(leave[j]<=arrive[i] or arrive[j]>=leave[i]))
                    {
                               ++count;
                    }
                    if(count>max)
                    max=count;
            }

    
    }
    cout<<count<<"\n";
}
    return 0;

}

instead of “cout<<max<<endl” you have written “cout<<count<<endl;”.
even after correcting that your logic is wrong.
consider the test case
1
4
1 3 5 9
4 12 8 10
answer is 2 where as your program prints 4.
for a given interval you are calculating the maximum no of intervals which have intersection with the given interval.
now in the given test case 2nd interval has intersection with 1,2,3 and 4 intervals and the answer is printed as 4 rather than 2.
hope this helps :slight_smile:

start from hr=0; increase hour(hr++), if you encounter arrival(arr[i]) then increase guest(count++), if you encounter departure(dep[i]), then decrease guest(count–). meanwhile, keep record of maximum guest number(if(count>max) max=count). print out max.

//