Playing with mobile numbers
Easy Accuracy: 29.7% Submissions: 486 Points: 2

Given a number in form of a string s. The task is to find whether the number is valid indian mobile number or not.
Rules for valid :-indian mobile number

  1. The number should contain 10 or 11 or 12 digits.
  2. If it contains 10 digits, then first  digit should be 7 or 8 or 9.
  3. If it contains 11 digits, then first  digit should be 0 and second rule follwed.
  4. If it contains 12 digits, then first two digits should be 91 and second rule followed 

Example 1:

Input: s = "912345678999"
Output: 1

Example 2:

Input: s = "123456789"
Output: 0

 

Your Task:
You don't need to read or print anything. Your task is to complete the function is_valid() which takes s as input parameter and returns 1 if it is valid indian mobile number otherwise returns 0.

 

Expected Time Complexity: O(1)
Expected Space Complexity: O(1)

Constraints:
1 <= |s| <= 13

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


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.

Playing with mobile numbers

Output Window