AlaaShaker's Weblog

// untitled …

Posts Tagged ‘Solutions

Alphabetic Phone Number Generator SOLVED [Problem of the Week]

with 4 comments

It’s been a while, huh? Well, for the second time, my apologies!

Anyway, the past problem was of medium difficulty, but there’s a trick that could make your life much easier. Do you know what a permutation is? This is a permutation problem. A definition of permutation is that a permutation of [ABC] is simply [ABC – ACB – BAC – BCA – CAB – CBA] .. all possible arrangements of the three letters. Think of our problem the same way, you just need all possible arrangements for the three characters corresponding to each number. Easier? Thanks to Abdalla Gamal for making our lives easier.

So, similar to the ACM problems, we’ll solve the standard permutation problem, where we get to print all possible arrangements of a set of digits. Then, we transform that to our problem. Read the rest of this entry »


Written by AlaaShaker

October 18, 2008 at 6:09 am

Count Open Lockers SOLVED [Problem of the Week]

with 4 comments

Seems this week’s problem was quite easy – five winners in less than two days!

Such problem is meant to look overwhelming. It would be very pointless if you thought of solving it by drawing a diagram of 100 lockers and literally ‘performed’ the 100 passes to know the solution. If this was an interview, be sure that you’ll be kicked out before you notice it!

First thing, forget the brute-force solution, since – again – it’s all about how you tackle the problem; that’s what the interviewer wants to see.
Go for a random number and give it a try – perhaps you could notice a sequence or a pattern. Let’s pick, mmm, 8?! Sounds good to me .. Read the rest of this entry »

Written by AlaaShaker

September 3, 2008 at 4:12 am

Link-the-Tree SOLVED [Problem of the Week]

with 2 comments

This week’s problem was was pretty easy – obviously for ACMers only!!

Anyway, here’s the solution. You were given a binary tree, not necessarily complete (most people overlooked this point, and hence they didn’t handle having nodes with only left or only right nodes – they just assumed that every node either has both or not!). The task was transforming that tree into a linked list by adding a Next pointer to the struct. Here’s a diagram that would make explaining such story much easier (my diagram, that’s why it sure looks better .. LOL):


On the left, you’ll find the original binary tree, along with two pointers, R and C, that I’ll use to solve the problem as you’ll see in a moment. On the right, this is the required output. Read the rest of this entry »

Written by AlaaShaker

August 28, 2008 at 9:15 pm

Posted in Problems

Tagged with , , ,

Secret Creator SOLVED [Problem of the Week]

with one comment

After a vigorous week of solutions to this hard problem, I will now post my solution … Read the rest of this entry »

Written by AlaaShaker

August 22, 2008 at 6:47 pm