Find the slope of the given number num. Slope of a number is the count of the minima and maxima digits in it. A digit is called a minima if the digit is lesser than the digit before and after it. Similarly a digit is called a maxima if the digit is greater than the digit before and after it.
Input : 1213321 Output : 2 1213321- The highlighted digit '2' is a maxima and highlighted digit '1' is a minima. Input : 273299302236131 Output : 6
Approach: Traverse the digits of the given number from the 2nd digit up to the 2nd last digit. For each digit check whether the digit is greater or smaller than digits before and after it. Get the count of such digits.
Slope = 2
Time complexity: O(n).
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Find points at a given distance on a line of given slope
- Slope of the line parallel to the line with the given slope
- Find the largest number smaller than integer N with maximum number of set bits
- Find minimum number to be divided to make a number a perfect square
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Find smallest possible Number from a given large Number with same count of digits
- Given number of matches played, find number of teams in tournament
- Find the minimum number to be added to N to make it a prime number
- Find the maximum number of composite summands of a number
- Find the smallest number whose digits multiply to a given number n
- Find maximum number that can be formed using digits of a given number
- Find the number of jumps to reach X in the number line from zero
- Find row number of a binary matrix having maximum number of 1s
- Find the largest good number in the divisors of given number N
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Find the number of ways to divide number into four parts such that a = c and b = d
- Find the total number of composite factor for a given number
- Find count of digits in a number that divide the number
- Find Next number having distinct digits from the given number N
- Find M-th number whose repeated sum of digits of a number is N
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.