Given an array of numbers and a string, determine whether the pattern matches (return true/false), e.g. [1,2,1,2] with "dog cat dog cat" -> true. Extend this so that each position can be a set of candidate numbers (e.g. [[1,2],[2],[1,2],[1,2,3,4]]) and you must choose one number per position such that the whole sequence still forms a valid pattern match ('metapatterns'). Asked in the onsite_or_phone_screen stage. This is a Vanta software engineer interview question based on LeetCode "Word Pattern II" with a nested-array/backtracking twist.
candidates is a list of integer lists, one list per word. A match is bijective: equal numbers must map to equal words, and equal words must map to equal numbers. Return a boolean.
def matches_metapattern(candidates, text):