PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4
Author: iceknight1093
Tester: sushil2006
Editorialist: iceknight1093
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
Given a string of length 3, can it be rearranged to form the word “cat”?
EXPLANATION:
There are several different solutions possible.
- Check if the string contains the three letters “c”, “a”, and “t”.
If it has all three, it can be rearranged to form “cat”, since its length is 3; otherwise it cannot. - Alternately, note that there are only 6 possible rearrangements of “cat”, namely:
“act”, “atc”, “cat”, “cta”, “tac”, “tca”.
You can check if the input string is one of these 6.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
CODE:
Editorialist's code (PyPy3)
s = input()
if s.count('c') > 0 and s.count('a') > 0 and s.count('t') > 0: print('Yes')
else: print('No')