AlaaShaker's Weblog

// untitled …

Alphabetic Phone Number Generator [Problem of the Week]

with 15 comments

Mmm, not quite problem of the “week” since it has been a while since I last posted a problem – I had a busy few weeks, my apologies!

Anyway, let’s move to the problem – another Microsoft interview problem. Sure you’ve all seen how phone pads hold three letters of the alphabet for every number you can press (except for 1 and 0). Check the photo below to know what I mean …

Phone Pad

The problem is simple. The input is a distinct, seven-digit number. The required output is all seven-character strings that could be generated from this number. For the sake of the problem, assume we have a different phone-pad layout as follows:

0: a, b, c
1: d, e, f
2: g, h, i
3: j, k, l
4: m, n, o
5: p, q, r
6: s, t, u
7: v, w, x
8: y, z, A
9: B, C, D

So, for a three-digit number [012], these are all possible combinations of strings generated from such number according to the above dictionary:

[     012     ]
adg adh adi aeg
aeh aei afg afh
afi bdg bdh bdi
beg beh bei bfg
bfh bfi cdg cdh
cdi ceg ceh cei
cfg cfh cfi

Results will be treated the ACM way this time – results comparison. No code submissions. I want the results for the number:

0267451

I want the full output: All generated strings …

Don’t post that HERE in the comments!

Post only the number of strings generated, then paste the strings anywhere and send me the link or email them .. Only if the number of strings is correct, I will check the results!

Find the problem solution here

Advertisements

Written by AlaaShaker

October 3, 2008 at 12:12 am

15 Responses

Subscribe to comments with RSS.

  1. There’s a trick .. I’m warning .. so read properly this time!!!

    AlaaShaker

    October 3, 2008 at 4:51 am

  2. Using the multiplication rule (Probability Theory):
    3 * 3 * 3 * 3 * 3 * 3 * 3 = ( 3 ^ 7 ) = 2187 combinations.

    A tree would make a hell of a good job to illustrate the idea, now if you are interested in the output just lemme know :p

    Metal_

    October 3, 2008 at 6:32 am

  3. To Metal_:
    You’re so right about the count. I guess it’s obvious I do want the output – sure a tree will do, and I won’t feel any sorry for you mate πŸ˜€ loooool

    AlaaShaker

    October 3, 2008 at 12:42 pm

  4. FIRST WINNER: TeCNoYoTTa .. Congrats!

    AlaaShaker

    October 3, 2008 at 1:39 pm

  5. loool.. I was asked the same question too πŸ˜€ .. seems they don’t change their questions in the interviews !!!

    Roaa

    October 3, 2008 at 2:58 pm

  6. http://rafb.net/p/hTWRFd42.html

    I was kidding about the output for sure :] It’s was only 6 AM, woke up to get something to drink, check up on things and get back to bed…

    About the tree, it’s for illustrating the idea with a simple input, like 3-digit number, not for solving your 7-digit number input.

    Metal_

    October 3, 2008 at 5:22 pm

  7. SECOND WINNER: Metal_ .. 3 more to go .. πŸ˜€

    AlaaShaker

    October 3, 2008 at 10:58 pm

  8. awalan : alf alf alf mabrook , ana 3erft enk 5atbt πŸ˜€ 3obal ely a3rfhom πŸ˜€ balash ana , rabena yewfa2ak isa we dayman fe progress keda ,, ya rafe3 rasna :D:D

    sry for the upper output mss , tecno told me that i have to upload the output file
    here it is :
    http://www.2shared.com/file/4054546/13e1a1c9/mohamed_hesham.html

    Mohamed Hesham

    October 7, 2008 at 9:20 pm

  9. THIRD WINNER: Mohamed Hesham ..
    Thanks, man. Allah yebarek feeek .. w 3o2balak enta kaman πŸ˜›

    To Roaa: yeah, tell me about that! lol

    AlaaShaker

    October 9, 2008 at 1:58 am

  10. number of strings: 2187

    see them here:
    http://rafb.net/p/GofUnt52.html

    Tasniem Seliem

    October 9, 2008 at 2:16 pm

  11. FOURTH WINNER: Tasniem Seliem .. Good Job (Y)

    AlaaShaker

    October 9, 2008 at 2:19 pm

  12. Amal Hussein

    October 10, 2008 at 9:16 pm

  13. number of strings generated is 2187

    5olio

    October 11, 2008 at 12:46 am

  14. […] the past problem was of medium difficulty, but there’s a trick that could make your life much easier. Do you […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: