FastPrepPrint Vertical Asterisk Bars

Print Vertical Asterisk Bars

Microsoft logoMicrosoft● EasyNEW GRADONSITE INTERVIEW

Updated

Problem statement

Given an array of nonnegative bar heights, return a top-to-bottom text drawing of vertical bars.

Each output row contains exactly one character per input bar: * when that bar reaches the row and a space otherwise. Bars are bottom-aligned. Return an empty array when there are no positive heights.

Function

drawVerticalBars(heights: int[]) → String[]

Examples

Example 1

heights = [3,1,2]return = ["*  ","* *","***"]

The first bar reaches all three rows, the second reaches only the bottom row, and the third reaches the bottom two rows.

Example 2

heights = [0,0]return = []

No bar has positive height, so there are no rows to draw.

Constraints

  • 0 <= heights.length <= 1000
  • 0 <= heights[i] <= 1000

More Microsoft Onsite Interview questions

Similar questions at other companies

Interview reports that mention this question

Microsoft interview experiences

All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public String[] drawVerticalBars(int[] heights) {
      // Write your code here.
    }

}
Checking account…