Print Vertical Asterisk Bars
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 <= 10000 <= heights[i] <= 1000
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Bounded Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
- Retry with an Attempt LimitOracle · ONSITE INTERVIEWOracle interview questions
- Extract Error Log ContextFlexTrade · ONSITE INTERVIEWFlexTrade interview questions
- Wildcard Character Array MatchGoogle · ONSITE INTERVIEWGoogle interview questions
- BitFont - Render a Kerned PairStripe · ONSITE INTERVIEWStripe interview questions
- Add Two Numbers Given as Digit ArraysCapital One · ONSITE INTERVIEWCapital One interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
- Hex Dump FormatterWaymo · ONSITE INTERVIEWWaymo interview questions