Heatmap Cell Symbols

Hard ⏱ 18 min 26% acceptance ★★★★☆ 4.4
Convert a 2D grid of numeric intensities into symbols: values below 3 become '.', 3-6 become '*', above 6 become '#'. Write heatmap(grid) preserving the 2D shape with nested comprehensions and a chained conditional expression.

Examples

Example 1
Input
heatmap([[1, 5], [9, 3]])
Output
[['.', '*'], ['#', '*']]
Explanation

1→., 5→*, 9→#, 3→*.

Constraints

  • Preserve the row structure.
  • Boundaries: v < 3 → '.', v <= 6 → '*', else '#'.

Topics

List Comprehensionsnested conditional expression

Companies

NetflixMeta

Hints

Hint 1

Chain: '.' if v < 3 else '*' if v <= 6 else '#'.

Hint 2

Wrap in an outer comprehension per row.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.