Grateful …
You are not checking for middle cases where minimum group can be between Some max groups . Besides these min can never be 10 as there are only 8 people .
Just check for these .
Hi, logan_Pradeep
The way you have given the soultion is AWESOME and clever as well.
Can you please tell me how you approached this solution, I know your experience was there, but apart from that, how you think a newbie can also approach this, like any previous problem which helped you with this approach. Please elaborate.
@soumya_8596 always keep pen and paper with you and write keypoints of question on paper and then use the given testcases of problem and try to recognize pattern where this problem is going to converge and we all know practice is most important.
Thank You Pradeep, that was nice. Just I want to add, I do use pen and paper first,I also try to find as many edgecase as possible, then I put them into some condition, to get the answer. But that soution I get is not enough for submission. But your code is handling all edge cases with just some little conditions…If you look at my code here, you can tell where do I lag, what is wrong in my way. Please don’t stretch for my code, or get worry. Thank you for your time and words.
/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t–>0)
{
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
int max=1;
int min=n;
int m=1;
for(int i=1;i<n;i++)
{
if((a[i]-a[i-1])<=2)
{
max++;
}
else
{
if(min>max)
{
min=max;
}
if(m<max)
{
m=max;
}
max=1;
}
}
if((a[n-1]-a[n-2])>2)
{
min=1;
}
if(m<max)
{
m=max;
}
System.out.println(min+" "+m);
}
}
}
PLEASE TELL WHY SUBTASK 2 IS FAILING
PLEASE HELP TO CORRECT TO THE CODE
int t;
scanf("%d", &t);
while (t--)
{
int n;
int min = 1000, max = -1;
scanf("%d", &n);
int a, b, c = 1;
scanf("%d", &a);
for (int i = 0; i < n - 1; i++)
{
int f = 0;
scanf("%d", &b);
if (b - a < 3)
{
c++;
f = 1;
}
else if (b - a > 2)
{
f = 0;
}
if (f == 0 || i == n - 2)
{
if (max < c)
{
max = c;
}
if (min > c)
{
min = c;
}
c = 1;
}
a = b;
}
printf("%d %d\n", min, max);
}
return 0;