HATTRICK - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: notsoloud
Tester: mexomerf
Editorialist: iceknight1093

DIFFICULTY:

TBD

PREREQUISITES:

None

PROBLEM:

Given the results of 6 balls of an over in a cricket match, decide whether there’s been a hattrick or not.

EXPLANATION:

Let A_i denote the result of the i-th ball.
Then, there’s a hattrick if and only if one of the following holds:

  • A_1 = A_2 = A_3 = \texttt{W}
  • A_2 = A_3 = A_4 = \texttt{W}
  • A_3 = A_4 = A_5 = \texttt{W}
  • A_4 = A_5 = A_6 = \texttt{W}

Check each condition individually using if conditions, or use a loop for nicer implementation; then print Yes or No appropriately.

TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (Python)
for _ in range(int(input())):
    a = input().split()
    hattrick = False
    for i in range(4):
        if a[i:i+3].count('W') == 3: hattrick = True
    print('Yes' if hattrick else 'No')