- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Let us see the following implementation to get better understanding −
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))
- In php, is 123==0123?
- Flip Columns For Maximum Number of Equal Rows in Python
- Flip and Invert Matrix in Python
- Program to count minimum number of operations to flip columns to make target in Python
- bitset::flip() in C++ STL
- Random Flip Matrix in C++
- Flip to Zeros in C++
- Flip Game II in C++
- Flip Effect with CSS
- Flip Equivalent Binary Trees in C++
- Flip Animation Effect with CSS
- What is D Flip Flop?
- What is T Flip Flop?
- Flip In X Animation Effect with CSS
- Flip In Y Animation Effect with CSS