Difficult Problems
Easy Accuracy: 37.5% Submissions: 16 Points: 2

Given a Number N in String form, Print 1 If the digits of the number are in non-decreasing or non-increasing order, else print 0.

 

Example 1:

Input:
N = "1233"
Output:
1
Explanation:
The digits of the number are in non-
decreasing order. So, the Output is 1.

Example 2:

Input:
N = "1263"
Output:
0
Explanation:
The digits of the number are neither in
non-decreasing nor in non-increasing order.
So, the Output is 0.

 

Your Task:
You don't need to read input or print anything. Your task is to complete the function difProblem() which takes a String N as input and returns 0 or 1.

 

Expected Time Complexity: O(|N|)
Expected Auxiliary Space: O(1)

 

Constraints:
1 <= |N| <= 105

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.