
- 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
123 Number Flip in Python
Suppose we have an integer n, where only 1, 2, and 3 these digits are present. We can flip one digit to a 3. Then find the maximum number we can make.
So, if the input is like 11332, then the output will be 31332
To solve this, we will follow these steps −
li := a list by digits of n
for x in range 0 to size of li - 1, do
if li[x] is not '3', then
li[x] := '3'
return the number by merging digits from li
return n
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, n): li = list(str(n)) for x in range(len(li)): if li[x] != '3': li[x] = '3' return int(''.join(li)) return n ob = Solution() print(ob.solve(11332))
Input
11332
Output
31332
- Related Articles
- Flip Columns For Maximum Number of Equal Rows in Python
- Flip and Invert Matrix in Python
- 123 +9367 = _____
- In php, is 123==0123?
- Program to count minimum number of operations to flip columns to make target in Python
- How to flip an image in OpenCV Python?
- Simplify $7+123\div 7$.
- Flip to Zeros in C++
- Flip Game II in C++
- bitset::flip() in C++ STL
- Random Flip Matrix in C++
- How can we divide 44 and 123?
- What is 123 rounded to nearest tens?
- Flip Equivalent Binary Trees in C++
- Flip Effect with CSS

Advertisements