Skip to content
DeepForgeby svx
All problems

Minimax Value 2-Ply

Problem

Solve a shallow two-ply game tree where the root maximizes and each child minimizes.

tree[i] is the list of leaf values under the i-th minimizing child. Return [best_child_index, minimax_value], choosing the smallest index on ties.

Hint

The opponent minimizes inside each child, so the root picks the best worst case.

Test cases

case 1
in: [[[3,5],[2,4],[6,1]]]
expected: [0,3]
case 2
in: [[[1],[0]]]
expected: [0,1]
case 3
in: [[[2,2],[2,2]]]
expected: [0,2]
case 4
in: [[[7]]]
expected: [0,7]
Starter codePython
def minimax_2ply(tree):
    # Your code here
    pass

4 test cases · run your code against them in the editor