Given a mobile number and some conditions for a fancy number, find if the given number is fancy. A 10 digit mobile number is called fancy if it satisfies any of the following three conditions.
- A single number occurs three consecutive times. Like 777.
- Three consecutive digits are either in increasing or decreasing fashion. Like 456 or 987.
- A single digit occurs four or more times in the number. Like 9859009976 – here the digit 9 occurs 4 times.
Input : 9859009976
Output : Yes
The given mobile number satisfies condition
three given above.
Input : 7609438921
Output : No
None of the given three conditions satisfy.
Idea is to convert number into string using to_string so that it becomes easy to traverse. For condition three to count the frequency of every number a basic concept of string hashing is used.
Source :Oracle Interview Set
Below is the solution of above problem.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Mobile Numeric Keypad Problem
- Convert a sentence into its equivalent mobile numeric keypad sequence
- Analyzing Mobile Data Speeds from TRAI with Pandas
- Getting Started with Cross-Platform Mobile Application using Flutter
- Count of buttons pressed in a keypad mobile
- Check a given sentence for a given set of simple grammer rules
- Check whether given string can be generated after concatenating given strings
- Queries to check whether a given digit is present in the given Range
- Check if given Binary string follows then given condition or not
- Check whether a given number is even or odd
- Check if a given string is a valid number (Integer or Floating Point) | SET 1(Basic approach)
- Check if a given string is a valid number (Integer or Floating Point) in Java
- Check if a given string is a valid number (Integer or Floating Point) in Java | SET 2 (Regular Expression approach)
- Check whether given floating point number is even or odd
- Check if a number is in given base or not
- Check if a number has digits in the given Order
- Check if the given decimal number has 0 and 1 digits only
- Generate number with given operation and check if it is palindrome
- Check whether the given floating point number is a palindrome
- Check if string remains palindrome after removing given number of characters
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.