![]() |
Given a number N without leading 0s, the task is to find the maximum number formed after replacing any two adjacent digits by their sum only once. Examples:
Approach: The problem can be solved based on the following observation: There can be two cases:
Follow the steps mentioned below to implement the idea:
Below is the implementation of the above approach : C++14
Java
Python3
C#
Javascript
Output
10012 Time Complexity: O(M) where M is the number of digits in the number. |
Reffered: https://www.geeksforgeeks.org
Greedy |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |