<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KVGHS6G" height="0" width="0" style="display:none;visibility:hidden"></iframe>

Brex计算机科学面试真题

职位分类
全部
数据相关
计算机科学
人工智能
产品经理
BQ
面试题
全部(3)
OOD(0)
Algorithm(0)
System Design(0)
高频题(0)
Math(0)
全部(3)
OOD(0)
Algorithm(0)
System Design(0)
高频题(0)
Math(0)
1.Discounted Card Purchase Functions
2.Function to Execute Card Purchase
3.Function to Check Card Purchase Ability
1. Discounted Card Purchase Functions
Modify the 'can_purchase' and 'purchase' functions to account for discounts a player receives from cards they already own. The discounts come from the number of red, blue, and green gems on the cards in hand. Write test cases to ensure your modified functions work correctly.
2. Function to Execute Card Purchase
Write a function named 'purchase' that allows a player to purchase a card given their collection of gems. If the player can purchase the card, add it to the player's cards; if not, return false. Include test cases to verify the functionality of your function.
3. Function to Check Card Purchase Ability
Write a function named 'can_purchase' that determines if a player can afford a particular card given their collection of gems. The function should return true if the player can afford the card, and false otherwise. Ensure to write test cases to validate your function.