Flexport OA Interview Question: Card Purchase Validation

18 Views
No Comments

Point value -> 2

Cost -> 5B

3G

Card Color <- G

Notation: Red – R, Blue – U, Black – B, Green – G, White – W

In this game, players will have a set of colored tokens (Red, Blue, Green, Black, White). Their objective is to purchase cards using those tokens.

Cards will have a cost of some number of the above listed colored tokens. For example, a card can cost 2 blue tokens and 1 green token. If a player has 2 blue tokens and 1 red token, they cannot buy the card because they do not have the necessary green currency.

The goal for this part is to implement a function that determines if a card can be purchased by a particular player given the current state of the game. How you choose to represent the purchase, game state, and function signature is completely up to you.

This problem asks you to design a representation for the player state and card cost, then implement a function that checks whether a card can be purchased. The key idea is to model both sides as color-to-count mappings and verify that the player has at least as many tokens as required for each color. If any required color is missing or insufficient, the purchase is invalid. The task is mainly about clean data modeling and straightforward validation logic.

END
 0