Leetcode 2806: Account Balance After Rounded Purchase

grid47
grid47
Exploring patterns and algorithms
Jan 31, 2024 4 min read

You have a bank account with a balance of 100 dollars. You are given a purchase amount and need to round it to the nearest multiple of 10. Then, deduct the rounded amount from your account balance and return the remaining balance.
Problem
Approach
Steps
Complexity
Input: You are given an integer 'purchaseAmount' representing the price of an item you wish to buy.
Example: Input: purchaseAmount = 18
Constraints:
• 0 <= purchaseAmount <= 100
Output: Return the bank account balance after the rounded amount has been deducted.
Example: Output: 80
Constraints:
Goal: Calculate the nearest multiple of 10 for the given purchase amount and update the bank balance.
Steps:
• 1. Round the 'purchaseAmount' to the nearest multiple of 10.
• 2. Subtract the rounded amount from the initial balance of 100 dollars.
• 3. Return the updated balance.
Goal: The purchase amount will be a non-negative integer less than or equal to 100.
Steps:
• 0 <= purchaseAmount <= 100
Assumptions:
• The purchase amount is always a non-negative integer and will be rounded to the nearest multiple of 10.
Input: Input: purchaseAmount = 18
Explanation: The nearest multiple of 10 to 18 is 20. So the account balance becomes 100 - 20 = 80.

Input: Input: purchaseAmount = 8
Explanation: The nearest multiple of 10 to 8 is 10. So the account balance becomes 100 - 10 = 90.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus