 # IPL_T - Editorial

Author: Prathamesh Sogale
Tester: Prathamesh Sogale
Editorialist: Ram Agrawal

EASY

loops

# PROBLEM:

It is IPL Season and the first league match of Vaibhav’s favorite team, “Chennai Super Kings”. The CSK team is playing at the IPL after 2 years and like all Dhoni lovers, Vaibhav is also eagerly awaiting to see Dhoni back in action.

After waiting in long queues, Vaibhav succeeded in getting the tickets for the big match. On the ticket, there is a letter-code that can be represented as a string of upper-case Latin letters.

Vaibhav believes that the CSK Team will win the match in case exactly two different letters in the code alternate. Otherwise, he believes that the team might lose. Please see note section for formal definition of alternating code.

You are given a ticket code. Please determine, whether CSK Team will win the match or not based on Vaibhav’s conviction. Print “YES” or “NO” (without quotes) corresponding to the situation.

``````Note!
Two letters x,yx,y where x=yx=y are said to be alternating in a code, if code is of form "xyxyxyxyxyxy...".
``````

# QUICK EXPLANATION:

In this question, you have to check that exactly two different letters in the string alternate.

# EXPLANATION:

In this question you have to traverse through the string and check that at every odd index, there is the same character and at every even position, there are the same characters.

# SOLUTIONS:

Setter's Solution
``````/* 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
{
static boolean ALT(String s)
{
for (int i = 0; i < s.length() - 2; i++)
{
if (s.charAt(i) != s.charAt(i + 2))
{
return false;
}
}

return s.charAt(0) != s.charAt(1);
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
sc.nextLine();
while (t-- != 0){
String s = sc.nextLine();
if(ALT(s)) System.out.println("YES");
else System.out.println("NO");
}
}
}
``````
Tester's Solution
``````#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int main() {
int T;
cin>>T;
for(int i=0;i<T;i++)
{
string S;
cin>>S;
int flag=1;
int len=S.length();
if(S==S)
{
flag=0;
}
for(int i=0;i<len-2;i++)
{
if(S[i]!=S[i+2])
{
flag=0;
}

}

if(flag==0)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
}
}
return 0;
}
``````
Editorialist's Solution
``````T=int(input())
for ii in range(T):
str1=input()

count=1
l1=[]
l2=[]

for ele in str1:
if count%2==1:
l1.append(ele)
else:
l2.append(ele)
count+=1

# index+=1
# print(l1)
# print(l2)
if len(l1) or len(l2) %2==1:
if len(set(l1))>1:
print("NO")

temp1=len(set(l1))
temp2=len(set(l2))
if temp1==temp2:
print("YES")
``````