Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Stock Price Fluctuation Coding

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Stock Price Fluctuation Coding. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Model stock price updates for a Jira Marketplace analytics feed. Each update associates a timestamp with a price, and a later update at the same timestamp replaces the previous value.

Implement stock_price_fluctuation(operations), which processes operations in order and returns the results of all query operations. Use a hash map to store the latest price for each timestamp and priority queues to retrieve minimum and maximum prices efficiently. Because Python heaps do not support arbitrary deletion, remove outdated heap entries lazily when they reach the top.

Formal Specification

  • Input: operations, a list of operation lists. Each operation is one of:
    • ['update', timestamp, price]
    • ['current']
    • ['maximum']
    • ['minimum']
  • timestamp and price are integers.
  • Output: A list of integers containing results for query operations in their original order.
  • Every query occurs after at least one update.

Constraints

  • 1 <= len(operations) <= 10^5
  • 1 <= timestamp <= 10^9
  • 0 <= price <= 10^9
  • Each query follows at least one update
  • A timestamp may be updated multiple times

Function Signature

def stock_price_fluctuation(operations):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output