PIXELBANKv9.1.0
Menu

Greedy Action from Action Values

Problem Statement

Given a list of action values q (one entry per action), return the index of the greedy action — the action with the highest value. Break ties by choosing the smallest index.

Implement greedy_action(q).

Example:

Input:
greedy_action([0.1, 0.5, 0.3])
Output:
1
Reasoning:
  • Initialize the candidate for the greedy action to the first index, setting the current best value to 0.10.1 at index 00.
  • Compare the value at index 11 (0.50.5) against the current best value (0.10.1); since 0.5>0.10.5 > 0.1, update the best index to 11 and the best value to 0.50.5.
  • Compare the value at index 22 (0.30.3) against the current best value (0.50.5); since 0.3≯0.50.3 \ngtr 0.5, the best index remains 11.
  • The final output is 1

Constraints:

  • 1 <= len(q) <= 1000
  • Values may be negative.
  • On ties, return the lowest 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 Action from Action Values - Easy | PixelBank