Posts Tagged ‘Code’
Link-the-Tree SOLVED [Problem of the Week]
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 »
Link-the-Tree [Problem of the Week]
Seems that last week’s problem was a bit difficult as Fouad stated in his last problem, so this weeks it’s an easier one .. not that easy though. It should be easy for all ACMers .. we’ll see!
I first met this problem in a physical Microsoft technical interview (and solved it a7l), which stresses how being an ACMer helped me a lot in passing interviews. Actually, that Microsoft interview is broken into four interviews: three in problem solving (= ACM) and one in System Architecture, Analysis and Design.
Anyway, here’s how this problem goes ..

You have a binary tree, not necessarily complete, where each Node holds two pointers (left and right) and a character as an identifier. Read the rest of this entry »
Secret Creator SOLVED [Problem of the Week]
After a vigorous week of solutions to this hard problem, I will now post my solution … Read the rest of this entry »
Secret Creator [Problem of the Week]
After the Design Patterns course has ended in FCIS, and following up with the wicked problems of my friend, Fouad, I decided to post a code design problem I heard lately …
class Secret
{
// TODO: class body goes here ..
}
class Creator
{
// TODO: class body goes here ..
}
You have two classes: Secret and Creator.
Code both classes such that no other class than Creator is allowed to instantiate a local object of Secret. In other words, I can create an object of Secret as long as this code is inside Creator. If I’m inside any other class than Creator, I can’t!!! Read the rest of this entry »

RSS - Posts