Trains the technique from
LeetCode 1257Smallest Common RegionThis 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 survey is organised into zones. Each entry of regions names a zone first and then the zones lying directly inside it. A zone lies inside another when it is named directly inside it, or inside something that does.
No zone lies directly inside more than one zone, and one zone holds all the others.
Given two distinct zone names region1 and region2, return the name of the innermost zone that holds both of them. A zone counts as holding itself.
Example 1
Both sites lie directly inside "North", so that is the innermost zone holding them both.
Example 2
One site lies inside "North" and the other inside "South", and the innermost zone holding both of those is "World".
Example 3
A zone counts as holding itself, and "Alba" lies inside "North", so "North" holds them both.
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 innermost_holder(regions: list[list[str]], region1: str, region2: str) -> str:public String innermostHolder(List<List<String>> regions, String region1, String region2)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.