An intuitive approach(C++)!

Problem Link: Hotel Bytelandia Practice Coding Problem - CodeChef
Approach=>
At first we need to sort both arrays. When the events will be sorted, it will be easy to track the count of guests that have arrived but not departed yet. The total guests at one time can be found by taking the difference of arrivals and departures at that time and the maximum value of all times will be the final answer. If(arr[i]=dep[j]) means the arrival time is more than the departure time then- we have to reduce the total number of guests by one. So decrement count but increment j. Update the maxi with max(maxi, count) after each iteration of the while loop.

Code:
include
include <limits.h>
include
include
using namespace std;

int main() {
// your code goes here
int T;
cin>>T;
for(int t=0;t<T;t++)
{
int n;
cin>>n;
vector at(n);
vector dt(n);
for(int i=0;i<n;i++)
{
cin>>at[i];
}
for(int i=0;i<n;i++)
{
cin>>dt[i];
}
sort(at.begin(),at.end());
sort(dt.begin(),dt.end());
int i=0,j=0,cnt=0,maxi=INT_MIN;
while(i<n&&j<n)
{
if(at[i]<dt[j])
{
cnt++;
i++;
maxi=max(maxi,cnt);
}
else
{
cnt–;
j++;
}
}
cout<<maxi<<endl;
}
return 0;
}

@amanyadav31
what’s the problem??

@amanyadav31
this is my c++ code
hope it will help

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    int a[n],b[n];
	    int freq[1001]={0};
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	    }
	    for(int i=0;i<n;i++)
	    {
	        cin>>b[i];
	    }
	    for(int i=0;i<n;i++)
	    {
	        for(int j=a[i];j<b[i];j++)
	        {
	            freq[j]++;
	        }
	    }
	    int mx=0;
	    for(int i=0;i<=1000;i++)
	    {
	        mx=max(mx,freq[i]);
	    }
	    cout<<mx<<endl;
	}
	return 0;
}