Plot ASCII chart for time-price pairs
FanaticsSoftware Engineer · Technical ScreenLast updated
This question evaluates skills in array manipulation, coordinate mapping, and ASCII-based data visualization, focusing on transforming unsorted time-price pairs into a fixed 2D grid and handling point collisions and empty cells.
Given an unsorted array of (timestamp, price) integer pairs, write a function to render an ASCII chart of the time series. The x-axis must include every integer timestamp from the minimum to the maximum in ascending order; the y-axis must include every integer price from the maximum down to the minimum. Represent each observed (timestamp, price) point with a '' in its cell. Draw a rectangular frame with '+' at borders; the top and bottom borders consist of repeated "+-----" segments separated by '+', one segment per timestamp column. Each interior row begins and ends with '+', with spaces in between except where a '' appears. If multiple points fall in the same cell, show one '*'. If a timestamp or price level has no point, leave its cell blank. Return the chart as a list of strings. For example, input [(1, 2), (6, 3), (4, 5), (2, 2)] should produce a chart whose columns map to timestamps 1..6 and rows to prices 5..2. Explain your approach and analyze time and space complexity.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.