Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Track Remaining Cards Counter

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

Your question is Track Remaining Cards Counter. 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

An Ironclad Workflow Designer review queue contains uniquely identified cards. Implement a counter that reports how many cards remain as cards are drawn, returned, or queried.

Write a function that processes an initial collection of card IDs and an ordered list of operations. A draw operation removes a card, a return operation adds a previously drawn card back, and a display operation records the current number of remaining cards.

Formal Specification

Implement remaining_card_counts(card_ids, operations).

  • card_ids is a list of unique strings representing the cards initially in the queue.
  • operations is a list of two-element lists. Each operation is either ["draw", card_id], ["return", card_id], or ["display", null].
  • Return a list of integers containing the remaining-card count for every display operation, in order.
  • Every draw targets a currently remaining card, and every return targets a card that is currently absent.

Constraints

  • 0 <= len(card_ids) <= 10^5
  • 0 <= len(operations) <= 2 * 10^5
  • Card IDs are non-empty strings
  • Card IDs are unique in card_ids
  • Every draw targets a remaining card
  • Every return targets a card that is not remaining

Function Signature

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