2021年3月3日星期三

How to solve Permutation of a phone number problem

The Problem:

A company is distributing phone numbers to its employees to make things easier. the next digit cannot be equal to the last is the only rule for example 0223 is not allowed while 2023 is allowed. At least three digits will be excluded every time. Write a function that takes in a length of the phone number and the digits that will be excluded. The function should print all possible phone numbers.

I got this question in an interview and I have seen one like it before at my university. It is a permutation problem. My question is what is the best way or decent way to solve this without a million for loops.

I do understand that this is technically how it works

length of phone number = 3;

[0-9], [0-9] excluding the last digit, [0-9] excluding the last digit

but I am unsure on how the best way to turn this into code. Any language is accepted!

thank you:

Also I might be asking this in the wrong place. please let me know if I am.

https://stackoverflow.com/questions/66467140/how-to-solve-permutation-of-a-phone-number-problem March 04, 2021 at 09:06AM

没有评论:

发表评论