Given a number N. The task is to check if the digits of the number follow any of the below order:
- The digits are in strictly increasing order.
- Or, the digits are in strictly decreasing order.
- Or, the digits follow strictly increasing order first and then strictly decreasing.
If the number follows any of the above order then print YES otherwise print NO.
Input : N = 415 Output : NO Input : N = 123454321 Output : YES
Traverse the number from right to left by extracting each digit one by one. Keep a pointer to tell that whether the current sequence is descending or ascending sequence, -1 denotes strictly ascending and 1 denotes strictly descending sequence. At first the sequence should be strictly increasing as we are going from right to left. As we encounter a digit which is lesser than the previous digit, change the flag to decreasing(i.e -1) and while in increasing order we get any digit which is equal to the previous digit we directly print NO.
Below is the implementation of the above approach:
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Tidy Number (Digits in non-decreasing Order)
- Check if the sum of digits of number is divisible by all of its digits
- Largest number smaller than or equal to n and digits in non-decreasing order
- Check if the given decimal number has 0 and 1 digits only
- Check if two numbers have same number of digits
- Check if the Xor of the frequency of all digits of a number N is zero or not
- Check if the sum of digits of a number N divides it
- Check if the frequency of all the digits in a number is same
- Check if all digits of a number divide it
- Check if a number with even number of digits is palindrome or not
- Program to check if a number is divisible by any of its digits
- Program to check if a given number is Lucky (all digits are different)
- Check if a given number can be represented in given a no. of digits in any base
- Check whether sum of digits at odd places of a number is divisible by K
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.