PIXELBANKv9.1.0
Menu

Greedy Policy from Action Values

Problem Statement

Policy improvement makes the policy greedy with respect to the current action values. Given a matrix Q where Q[s] is the list of action values at state s, return the greedy deterministic policy: a list where entry s is the best action index at that state (lowest index on ties).

Implement greedy_policy(Q).

Example:

Input:
greedy_policy([[1.0, 2.0], [3.0, 0.0]])
Output:
[1, 0]
Reasoning:
  • Process the first state with action values [1.0,2.0][1.0, 2.0]: compare the values to find the maximum, where 2.0>1.02.0 > 1.0, so the greedy policy selects action index 11.
  • Process the second state with action values [3.0,0.0][3.0, 0.0]: compare the values to find the maximum, where 3.0>0.03.0 > 0.0, so the greedy policy selects action index 00.
  • The final output is [1, 0]

Constraints:

  • 1 <= num states <= 1000, each Q[s] non-empty.
  • Break ties toward the lowest action index.
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Greedy Policy from Action Values - Easy | PixelBank