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)
- Largest number smaller than or equal to n and digits in non-decreasing order
- Check if the Xor of the frequency of all digits of a number N is zero or not
- Check if the frequency of all the digits in a number is same
- Check if the sum of digits of a number N divides it
- Check if two numbers have same number of digits
- Check if all digits of a number divide it
- Check if the given decimal number has 0 and 1 digits only
- Check if a number with even number of digits is palindrome or not
- Check if a given number divides the sum of the factorials of its digits
- Check if a given number can be represented in given a no. of digits in any base
- Program to check if a given number is Lucky (all digits are different)
- Check whether sum of digits at odd places of a number is divisible by K
- Check if the number is even or odd whose digits and base (radix) is given
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.