Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 803109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:42:23+00:00 2026-05-14T23:42:23+00:00

Given a phone keypad as shown below: 1 2 3 4 5 6 7

  • 0

Given a phone keypad as shown below:

1 2 3
4 5 6
7 8 9
  0

How many different 10-digit numbers can be formed starting from 1? The constraint is that the movement from 1 digit to the next is similar to the movement of the Knight in a chess game.

For eg. if we are at 1 then the next digit can be either 6 or 8
if we are at 6 then the next digit can be 1, 7 or 0.

Repetition of digits are allowed – 1616161616 is a valid number.

Is there a polynomial time algorithm which solves this problem? The problem requires us to just give the count of 10-digit numbers and not necessarily list the numbers.

EDIT: I tried modeling this as a graph with each digit having 2 or 3 digits as its neighbors. Then I used DFS to navigate upto the depth of 10 nodes and then increment the count of numbers each time I reached the depth of 10. This obviously is not polynomial time. Assuming each digit had just 2 neighbors, this would have required at least 2^10 iterations.

The variable here is the number of digits. I have taken the eg. of 10 digit numbers. It could as well be n-digits.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:42:24+00:00Added an answer on May 14, 2026 at 11:42 pm

    Sure it can be done in polynomial time. It’s an excellent exercise in dynamic programming or memoization.

    Lets assume N (the number of digits) equals 10 for the example.

    Think of it recursively like this: How many numbers can I construct using 10 digits starting from 1?

    Answer is

    [number of 9-digit numbers starting from 8] +
    [number of 9-digit numbers starting from 6].
    

    So how many “9-digit numbers starting from 8” are there? Well,

    [number of 8-digit numbers starting from 1] +
    [number of 8-digit numbers starting from 3]
    

    and so on. Base case is reached when you get the question “How many 1-digit numbers are there starting from X“ (and the answer is obviously 1).

    When it comes to complexity, the key observation is that you reuse previously computed solutions. That is for instance, the answer to “how many 5-digit numbers starting from 3“ there are, can be used both when answering “how many 6-digit numbers are there starting from 8“ AND “how many 6-digit numbers are there starting from 4“. This reuse make the complexity collapse from exponential to polynomial.

    Let’s take a closer look at the complexity of a dynamic programming solution:

    Such implementation would fill in a matrix in the following way:

    num[1][i] = 1, for all 0<=i<=9   -- there are one 1-digit number starting from X.
    
    for digits = 2...N
        for from = 0...9
            num[digits][from] = num[digits-1][successor 1 of from] +
                                num[digits-1][successor 2 of from] +
                                ...
                                num[digits-1][successor K of from]
    
    return num[N][1]                 -- number of N-digit numbers starting from 1.
    

    The algorithm simply fills the matrix one cell at a time, and the matrix is of dimension 10*N, and thus runs in linear time.


    Wrote it down from the top of my head, please correct me if there are any typos.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that there are many sizes and color depths for different phones (even for
i need an sms service that can gives me a phone number and then
Suppose you want to write a program that implements a simple phone book. Given
Given a string of a mobile phone number, I need to make sure that
I have a Silverlight Windows Phone 7 app that pulls data from a public
Given that the phone starts in a staionary position, it would be possible to
Given a contact id, I can obtain various contact details (like name, phone, email-id,
I am trying to extract phone number in java from the given String i.e.
Given the DTD file below : !ELEMENT hotels (address+)> <!ELEMENT address (city,street,phone,hotelDetails)> <!ELEMENT hotelDetails
I just want to get email id of user having phone number given. so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.