COVID19 - Editorial

The link is not correct.

i solved that problem ā€¦but when i run my code on code i get runtimeException but when i submit it was correct and successfully submited

1 Like

It aint much but Its honest work

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.

1 Like

@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.

1 Like

I am beginner plz can someone help me print the minimum value in each test case.I am able to print the maximum.

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.

Broā€¦ its not gud to add more comments here. U can connect me on linkedln https://www.linkedin.com/in/pradeepshakya

whatā€™s wrong with my soln;

#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(tā€“){
int n, mn=INT_MAX, mx=1, temp=1;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n-1;i++){
temp=1;
while(abs(a[i]-a[i+1])<=2 && i<n-1){
temp++;
i++;
}
mx=max(temp,mx);
mn=min(temp,mn);
}
cout<<mn<<" "<<mx<<endl;
}
}

BRO can you check my code it passed all the test cases u r mentioning above
still i m getting TLE

/* package codechef; // donā€™t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* 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

Can some tell why itā€™s showing wrong.

#include <stdio.h>

int main()

{

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;

}