Digit Changes for a Multiple of 9
Updated
Problem statement
You are given a string num made only of decimal digits. It stands for a whole number, and leading zeros do not change its value.
You may change some digits of num, but only in these two ways:
- a digit
2may become a4; - a digit
3may become a9.
You can pick any set of the 2s and 3s to change, including none of them. No other digit can change.
Return true if some choice of changes makes the number a multiple of 9, and false otherwise.
Function
canMakeMultipleOfNine(num: String) → booleanExamples
Example 1
num = "322"return = trueThe digits add up to 3 + 2 + 2 = 7, so 322 is not a multiple of 9. Change one of the two 2s into a 4 to get 342. Its digits add up to 9, and 342 = 9 * 38. You do not have to change every 2.
Example 2
num = "1234"return = trueThe digits add up to 10. Changing only the 2 gives a digit sum of 12, and changing only the 3 gives 16. Changing both gives 1494, whose digits add up to 18, and 1494 = 9 * 166.
Example 3
num = "23"return = falseThe four possible numbers are 23, 43, 29 and 49. Their digit sums are 5, 7, 11 and 13, and none of them is a multiple of 9.
Constraints
1 <= num.length <= 10^5numcontains only the digits0to9.
More Nutanix Online Assessment questions
- Good SubsequencesOA · Seen Jul 2026
- Min Cost to Connect All PointsOA · Seen Jun 2026
- Gas Station Loop StartOA · Seen Aug 2025
- Number of Players (for MTS2)OA · Seen Oct 2024
- Work Schedules (for MTS2)OA · Seen Oct 2024
- Minimum Operations to Convert ArrayOA · Seen Apr 2024
- No Adjacent CharactersOA · Seen Apr 2024
- Build a BST From a ListOA · Seen Nov 2022
- Delete Even-Valued Nodes From a Linked ListOA · Seen Nov 2022
- Maximum Value of the Last RobotOA · Seen Aug 2021
Similar questions at other companies
- Binary CircuitAkuna Capital · OAAkuna Capital interview questions
- Return Exact Cash Register ChangeBank of America · OA
- Minimize Expression with ParenthesesPinterest · OAPinterest interview questions
- Minimum Digit Swaps for the Smallest DifferenceLSEG · OALSEG interview questions
- Minimize Difference Between Two NumbersMicrosoft · OAMicrosoft interview questions
- Maximum Binary Circuit Segregation CostAdobe · OAAdobe interview questions
- Reorderable Task Scheduler With CooldownWaymo · PHONE SCREENWaymo interview questions
- Smallest Number With a Given Digit SumAmazon · ONSITE INTERVIEW
- Maximum Ones After K OperationsGoldman Sachs · OAGoldman Sachs interview questions
- Server InvestmentRippling · OARippling interview questions