Author - Soham Chakraborty
Tester- Abhisekh Paul Sayan Poddar
Editorialist- Soham Chakraborty
DIFFICULTY:
Cakewalk
PREREQUISITES:
Array , Loops , Conditional Statement.
PROBLEM:
- Checking that Odd terms are increasing or not.
- Checking that Even terms are Decreasing or not.
Time Complexity O(n)
Space Complexity O(1)
Solution :
C++
Setters Code
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--)
{
long long n,i;
cin>>n;
long long int a[n];
for(i=0;i<n;i++)
cin>>a[i];
int flag=0;
long long int x=INT_MIN;
long long int y=INT_MAX;
for(i=0;i<n;i++){
if(i%2==0){
if(x>a[i]){
flag=1;
break;
}
else
x=a[i];
}
else{
if(y<a[i]){
flag=1;
break;
}
else
y=a[i];
}
}
if(flag)
cout<<"LOSE"<<endl;
else
cout<<"WIN"<<endl;
}
}
Python
Testers Code
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
c=len(a)
l=a[0]
m=a[1]
f=1
for i in range(2,c):
if (i+1)%2==1:
x=a[i]
if l<x:
l=x
else:
f=0
print("LOSE")
break
else:
y=a[i]
if y<m:
m=y
else:
f=0
print("LOSE")
break
if f==1:
print("WIN")
Java
Testers Code
import java.util.*;
class nov4 {
public static void main(String[]Args)
{
Scanner sc=new Scanner(System.in);
int t1=Integer.parseInt(sc.nextLine());
while(t1>0)
{
int n=Integer.parseInt(sc.nextLine());
String s[]=sc.nextLine().split(" ");
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=Integer.parseInt(s[i]);
}
int p=Integer.MIN_VALUE;
int t=0;
for(int i=0;i<n;i+=2)
{
if(a[i]<p)
{
t=-1;
break;
}
p=a[i];
}
p=Integer.MAX_VALUE;
for(int i=1;i<n;i+=2)
{
if(a[i]>p)
{
t=-1;
break;
}
p=a[i];
}
if(t==-1)
System.out.println("LOSE");
else
System.out.println("WIN");
t1--;
}
}
}