A warehouse wrist-scanner has its input keys arranged into three physical zones. Each zone covers a fixed set of lowercase letters, no two zones share a letter, and together the three zones cover every letter of the alphabet exactly once. Every crate in the warehouse carries a printed label made only of letters (the label's casing on the printout may mix upper and lower case, but tapping any letter -- of either case -- always presses the same physical key, so case does not affect which zone a letter belongs to). A label can be entered by an operator who is only allowed to tap keys from a single zone if and only if every letter of that label belongs to the same zone. Find every label that can be entered this way.
Print, one per line, exactly the labels that can be typed using keys from a single zone only -- preserving each label's original casing exactly as given, and in the same relative order as the input. If no label qualifies, print nothing.
Example 1
Input
abcdefghij klmnopqrs tuvwxyz 5 Bead Sort Fig Xyz Cab
Expected
Bead Fig Xyz Cab
Explanation
Zone 1 is a-j, zone 2 is k-s, zone 3 is t-z. "Bead" -> b,e,a,d all in zone 1: qualifies. "Sort" -> s,o,r are zone 2 but t is zone 3: mixed, excluded. "Fig" -> f,i,g all zone 1: qualifies. "Xyz" -> x,y,z all zone 3: qualifies. "Cab" -> c,a,b all zone 1: qualifies. Output: Bead, Fig, Xyz, Cab (Sort is excluded).
Example 2
Input
abcdefghij klmnopqrs tuvwxyz 4 AbC TUV Mop Fast
Expected
AbC TUV Mop
Explanation
Same zones as Example 1. "AbC" -> a,b,c all zone 1 (case ignored for zone lookup): qualifies, printed with its original casing "AbC". "TUV" -> t,u,v all zone 3: qualifies as "TUV". "Mop" -> m,o,p all zone 2: qualifies as "Mop". "Fast" -> f,a are zone 1 but s is zone 2 and t is zone 3: mixed, excluded. Output: AbC, TUV, Mop.
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 →