- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
Make three numbers Zero in Python
Let us suppose we have three numbers. The task is to count the total number of optimal steps to make all these numbers '0'.
a = 4 b = 4 c = 6
The total number of optimal steps to make all the numbers '0' is,
(4, 4, 6)
Removing '1' from 1st and 2nd number = (3, 3, 6)
Removing '1' from 1st and 3rd number = (2, 3, 5)
Removing '1' from 1st and 3rd number = (1 ,3, 4)
Removing '1' from 1st and 3rd number = (0 ,3 ,3)
Removing '1' from 2nd and 3rd number = (0 ,2, 2)
Removing '1' from 2nd and 3rd number = (0, 1, 1)
Removing '1' from 2nd and 3rd number = (0, 0, 0)
Thus, the total number of steps to make all the numbers zero is '7'
Approach to solve this Problem
To solve this particular problem, we will remove '1' from any two numbers such that the sum of these two numbers is greater than the last one. To find the minimum steps to make it zero, we will calculate the minimum number of steps.
- Take three numbers as the input.
- Sort the numbers in increasing order using the sort
- Check if the sum of two numbers is less than the third number, then return the sum.
- Since each time, we are removing '1' from any two numbers, it will take (n1+n2+n3)/2 steps to make all the numbers '0'.
def maxScore(a: int, b: int, c: int): a, b, c = sorted((a, b, c)) if a + b < c: return a + b return (a + b + c)//2 a=4 b=4 c=6 print(maxScore(a,b,c))
Running the above code will generate the output as,
For the given inputs a=4, b=4 and c=6, it will take seven steps to make all the numbers '0'. Hence, the program returns 7 as the output.
- Related Articles
- Make three numbers Zero in C++
- Program to find minimum one bit operations to make integers zero in Python
- Program to make the XOR of all segments equal to zero in Python
- Replace NaN with zero and infinity with large finite numbers in Python
- Check whether given three numbers are adjacent primes in Python
- Python program to find the maximum of three numbers
- Find the number of consecutive zero at the end after multiplying n numbers in Python
- Minimum operations to make XOR of array zero in C++
- How to Find the Largest Among Three Numbers using Python?
- How many three-digit numbers can you make with 0,5,9 by using each digit once?
- Replace NaN with zero and infinity with large finite numbers for complex input values in Python
- How to change the negative numbers to zero in Excel?
- Maximum Product of Three Numbers in C++