Codechef : Problem name " Difficulty Rating Order " solution in C#

 ===============================Solution=================================

using System;

public class Test

{

public static void Main()

{

    int t=Convert.ToInt32(Console.ReadLine());

for(int i=0;i<t;i++){

    bool flag=false;

    int N=Convert.ToInt32(Console.ReadLine());

    string[] array=Console.ReadLine().Split(' ');

    

    for(int k=1;k<N;k++)

    {

        if(Convert.ToInt32(array[k])<Convert.ToInt32(array[k-1]))

        {

            flag=true;

            break;

        }

    }     

    if(flag)

    Console.WriteLine("No");

    else if(flag == false)

    Console.WriteLine("Yes");

}

}

}

===========================Explanation=========================
After accepting all the numbers we are running through the list of numbers 
We started the index at 1 so that when we compare with i-1 index we will be ale to compare the elements of the array
As per problem statement if the list is not in ascending order we change the flag and print accordingly 

Comments