Mike and Mobile Keypad Problem

Mike, a young math enthusiast, is playing with his mom’s mobile phone, which has a keypad with 12 buttons (10 digits: 0-9, and 2 special characters: ‘*’ and ‘#’). His challenge is to find out how many different numbers he can generate by pressing exactly 'N' buttons. He follows these rules:

1. Mike only presses buttons with digits (0-9), never the ‘*’ or ‘#’.
2. The next button press must either be the same button or an adjacent button.
3. Initially, he can start pressing any button except ‘*’ or ‘#’.

Your task is to help Mike solve this problem, and due to potentially large results, output the answer modulo 10^9 + 7.

Input:

The first line of the input is an integer 'T', indicating the number of test cases.
Each of the next 'T' lines contains an integer N, the number of buttons to press.

Output:

For each test case, output the number of distinct numbers that can be formed by pressing exactly 'N' buttons on the keypad. Print each result on a new line.

Example:

Input:
2
1
2
Output:
10
36

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 5 * 104
  • Time Limit: 1 second
Note:
You do not need to print anything; the function implementation will handle this itself.
AnswerBot
4mo

Calculate the number of distinct numbers that can be formed by pressing 'N' buttons on a mobile keypad following specific rules.

  • Use dynamic programming to keep track of the number of distinct numbers ...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Interview Questions Asked at Amazon

Q. Could you describe the process for designing a data structure that allows for al...read more
Q. What is Java?
Q. Given two strings s and t, return true if they are equal when both are typed int...read more
Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits