A logistics company tracks each courier's deliveries day by day with one of three status codes: O for on-time, D for delayed, and M for missed entirely. A courier earns the monthly reliability badge only if both of the following hold for their log:
M), andDDD as a substring).Given a courier's log for the month, determine whether they earn the badge.
A single line containing the log: a string of length n made up only of the characters O, D, and M.
Print YES if the courier earns the reliability badge, otherwise print NO.
Example 1
Input
OMDDO
Expected
YES
Explanation
The log has exactly one 'M' (fewer than 2, OK) and its longest run of consecutive 'D' is 2 (positions 3-4, "DD"), never reaching 3. Both conditions hold, so the courier earns the badge: YES.
Example 2
Input
MDDDM
Expected
NO
Explanation
The log has two 'M' characters (fails the "fewer than 2" rule) and also contains "DDD" as a substring (fails the run rule). Either failure alone is enough, so the answer is NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →