Increase Number By 1 Problem Statement
Given an array of integers NUM
that consists of N
elements, where the array represents the digits of a number, your task is to add 1 to this number. The number is positive, and the digits are arranged so that the most significant digit is at the beginning of the array.
Example:
Input:
NUM = [1, 3, 2, 7]
Output:
[1, 3, 2, 8]
Explanation:
The input array represents the number 1327, and adding 1 results in 1328, giving the output [1, 3, 2, 8].
Constraints:
1 ≤ T ≤ 10^2
1 ≤ N ≤ 10^4
0 ≤ NUM[i] ≤ 9
- The leading zeros in the input should not appear in the output.
- The time limit for the operation is 1 second.
Note:
Input:
The first line contains an integerT
, the number of test cases.
Each test case consists of two lines:
- First line has an integerN
, the number of elements in the array.
- Second line containsN
space-separated integers representing the array elements.
Output:
For each test case, print the resulting array elements separated by space, each test case result in a new line.
Be the first one to answer
Add answer anonymously...
Top HashedIn by Deloitte Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in HashedIn by Deloitte Software Engineer
>
HashedIn by Deloitte Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app