Trains the technique from
LeetCode 290Word PatternThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A sorting line is set up from two written records of the same shift. code is a string of lowercase letters, one letter per item that came down the line. run names the bin each item was dropped into, the bin names given as lowercase words separated by single spaces, with no space at either end.
The two records fit when the letters and the bin names stand in for each other exactly: every occurrence of a given letter goes with the same bin name, and every occurrence of a given bin name goes with the same letter. So one letter may not cover two different bins, and one bin may not answer to two different letters. The two records must also describe the same number of items.
Return true if the two records fit and false otherwise. A bin name is one whole word: two names that merely share a first letter are different names.
Example 1
The letter m goes with rust both times it appears and n goes with amber, and neither bin is shared with another letter.
Example 2
The two letters are different but both items went into amber, so one bin would have to answer to two letters.
Example 3
The letter w goes with chalk and z with slate at the first two items, and the last two items reverse that pairing.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def code_fits_run(code: str, run: str) -> bool:public boolean codeFitsRun(String code, String run)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.