PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: iceknight1093
Tester: kingmessi
Editorialist: iceknight1093
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
A word is liked by Chef if it either starts with c or ends with f.
Given a 4-letter word, represented by string S, decide if it’s liked by Chef or not.
EXPLANATION:
The answer is Yes if at least one of these two conditions holds:
- S_1 = c
- S_4 = f
Note that this is assuming 1-indexing.
If using 0-indexing, check for S_0 = c, S_3 = f respectively.
Check both conditions using an if condition and print Yes or No appropriately.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (PyPy3)
s = input()
if s[0] == 'c' or s[3] == 'f': print('Yes')
else: print('No')