Matryoshka dolls are traditionally wooden dolls that can be nested by fitting smaller dolls into larger ones. Suppose lists can be nested similarly, placing smaller lists into larger ones, in the following sense:
List A can be nested inside List B if:
min(list A) > min(list B)max(list A) < max(list B)For example, if A = [2, 3, 9, 5] and B = [10, 2, 1], then A can be nested inside B, since:
min(A) = 2 > 1 = min(B) andmax(A) = 9 < 10 = max(B)Create a function that returns True if every single sub-list inside a list can be nested Matroyshka style, and False otherwise.
matryoshka([[2, 2, 7], [3, 4, 5, 6], [4, 5]]) ➞ True
# [4, 5] nested inside [3, 4, 5, 6], [3, 4, 5, 6] nested inside [2, 2, 7], etc.
# Dolls nested from largest to smallest.
matryoshka([[4, 5], [6, 3], [7, 6, 5, 4, 3, 2], [8, 1]]) ➞ True
# Dolls nested from smallest to largest.
matryoshka([[7, 1], [7, 6, 5, 4, 3, 2], [6, 3], [4, 5]]) ➞ False
# [7, 1] and [7, 6, 5, 4, 3, 2] share the same max.
# Second doll cannot be nested properly inside first doll.
matryoshka([[1, 5], [2, 6], [3, 7]]) ➞ False
# Elements are overlapping, cannot be nested.