PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • Medium
  • Fanatics
  • Coding & Algorithms
  • Software Engineer

Plot ASCII chart for time-price pairs

Company: Fanatics

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

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.

Quick Answer: 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 list of integer pairs (timestamp, price), render the time series as an ASCII chart and return it as a list of strings. If the input is empty, return an empty list. Otherwise, create one column for every integer timestamp from the minimum timestamp to the maximum timestamp, inclusive, in ascending order. Create one row for every integer price from the maximum price down to the minimum price, inclusive, in descending order. A cell contains a '*' if that exact (timestamp, price) pair appears at least once in the input; otherwise it is blank. Duplicate points should still display only one '*'. Each cell is 5 characters wide: use ' * ' for a filled cell and ' ' for an empty cell. Join cells in a row with '+' separators, and add a leading and trailing '+'. The top and bottom borders are made of '-----' segments joined by '+', for example '+-----+-----+'.

Constraints

  • 0 <= len(points) <= 10000
  • -10000 <= timestamp, price <= 10000
  • If points is non-empty, the rendered ranges are manageable: max(timestamp) - min(timestamp) <= 100 and max(price) - min(price) <= 100
  • Input may be unsorted and may contain duplicate pairs

Examples

Input: [(1, 2), (6, 3), (4, 5), (2, 2)]

Expected Output: ['+-----+-----+-----+-----+-----+-----+', '+ + + + * + + +', '+ + + + + + +', '+ + + + + + * +', '+ * + * + + + + +', '+-----+-----+-----+-----+-----+-----+']

Explanation: Timestamps span 1 through 6 and prices span 5 down to 2. Stars appear at (4,5), (6,3), (1,2), and (2,2).

Input: [(-1, 0), (1, -1), (-1, 0), (0, -1)]

Expected Output: ['+-----+-----+-----+', '+ * + + +', '+ + * + * +', '+-----+-----+-----+']

Explanation: This checks negative values and duplicates. The duplicate (-1, 0) still produces only one star in that cell.

Input: []

Expected Output: []

Explanation: With no points, there is no chart to draw.

Input: [(3, 7)]

Expected Output: ['+-----+', '+ * +', '+-----+']

Explanation: A single point produces one column, one price row, and matching top and bottom borders.

Solution

def solution(points):
    if not points:
        return []

    point_set = {tuple(point) for point in points}

    min_ts = min(t for t, _ in point_set)
    max_ts = max(t for t, _ in point_set)
    min_price = min(p for _, p in point_set)
    max_price = max(p for _, p in point_set)

    num_cols = max_ts - min_ts + 1
    border = "+" + "+".join(["-----"] * num_cols) + "+"

    chart = [border]
    for price in range(max_price, min_price - 1, -1):
        cells = []
        for ts in range(min_ts, max_ts + 1):
            if (ts, price) in point_set:
                cells.append("  *  ")
            else:
                cells.append("     ")
        chart.append("+" + "+".join(cells) + "+")
    chart.append(border)

    return chart

Time complexity: O(n + T * P), where n is the number of input pairs, T is the number of timestamp columns, and P is the number of price rows.. Space complexity: O(n + T * P), counting the set of unique points and the output chart..

Hints

  1. First normalize the chart bounds by finding the minimum and maximum timestamp and price.
  2. Use a set of pairs so you can test whether a cell should contain '*' in O(1) average time.
Last updated: May 15, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.