Problem 133855 · medium · Phase 01 Prerequisites & Setup

Vertical Bar Chart

nested loops · strings · conditionals

Draw a vertical bar chart. heights is a list of non-negative integers, one per bar. Return the picture as a list of strings from the top row down: the chart has max(heights) rows, and in each row the character for bar i is # if that bar reaches the row's level, otherwise .. The bottom row is level 1, the top row is level max(heights).

Examples

Input:  heights = [3, 1, 2]
Output: ["#..", "#.#", "###"]

Input:  heights = [2]
Output: ["#", "#"]

Constraints

  • 0 <= len(heights) <= 60, 0 <= heights[i] <= 30
  • Return [] if the list is empty or every height is 0.

Goals

  • Build a picture row by row from the top even though data is per column
  • Compare each bar's height against the current level
Starting Python…