Company: Sprinklr_11oct
Difficulty: medium
Gambler's Dice Problem Description You are given a perfect n -ary tree with k levels. The root is alone on level 1, every node on levels 1 through k - 1 has exactly n children, and every node on level k is a leaf. When k = 1 the tree is the root alone. For reference, a perfect binary tree ( n = 2 ) with 4 levels has 1, 2, 4 and 8 nodes on its four levels. Each node of the tree must be labeled with a number found on a die, that is, a number p with 1 <= p <= 6 . Different nodes may carry the same number. The labeled tree is called Gambler Friendly if the following holds: for every node of the tree, if it is labeled with a number p , then every node adjacent to it (its parent and its children) is labeled with a number q such that p and q are on adjacent faces of the die. A number is not adjacent to itself, so p != q . On a standard die the numbers on opposite faces sum to 7 (the pairs 1-6 , 2-5 and 3-4 ), so each face is adjacent to exactly the four faces that are neither itself nor