Friday, July 31, 2009

Technical Interview Questions

One of my roles in my new position at Adify is to interview computer scientists and software engineers who wish to join our team and company. When I look at nervous candidates, I remember being in their position. Not only I get excited for them, I also feel a huge sense of responsibility to be objective and fair.

One way I do this is by posing difficult technical questions that exclusively involve coding, while watching the candidate. I've been there; I don't expect you to be perfect. I just look at how your mind works when you're making design decisions, and what your first reactions are when you run into problems. For example, when I tell you "you have a bug, can you find it?" some candidates panic, and some fruitlessly keep rereading their code. The skilled ones just enter some input into their methods, as if unit testing manually, and that helps them discover the bug immediately.

I really wish I could simply guide the candidate towards the answer as if we were already part of a team; as if I was there to support them. But if I did that, we would never be able to differentiate and hire highly skilled people.

Another important aspect of my interviewing style is that I try to design my own questions. Most interview questions, meant to test fundamental computer science skills, are asked to death by now, and are enshrined in lists all over the Internet. I tend to collect the difficult questions I've been asked throughout my career, modify a well-known question to make it interesting, or design a new problem that abstracts away a challenge I've faced during a design phase. I am even willing to share my interview questions with you.

When you are watched over your shoulders while you are coding on the white-board, use the opportunity to verbalize your solution. Describe your thoughts in real-time, and tell me your design while you're working on it. It's a sign of a good engineer and it builds confidence. I have received passes by some great senior engineers in Microsoft, Google, Amazon and elsewhere before, by simply describing how I would solve the problem concisely, even though I didn't manage to complete coding it in time. When I see a smart design and a good effort, I show the same courtesy.

Monday, July 20, 2009

A start in Silicon Valley: Mastering progress and pleateau, with some book recommendations

"To love the plateau is to love the eternal now, to enjoy the inevitable spurts of progress and the fruits of accomplishment, then serenely to accept the new plateau that waits just beyond them. To love the plateau is to love what is most essential and enduring in your life."

From the book "Mastery: The Keys to Success and Long-Term Fulfillment" by George Leonard, author and Aikido instructor

I'm starting a new life. As I mentioned earlier, July tends to be the month in which I make major life-changing decisions. 12 years ago in July I immigrated from Iran to Canada. Five years ago in July I visited United States for the first time when I went to Manhattan, New York on the Independence Day. Two years ago I moved from Toronto, Canada to Seattle, Washington to work at Microsoft. Last year I was on a plane to Europe in July, to backpack 22 countries in 80 days. This year, it's July again.

So I decided to seek the waves of the sea of change. I packed my life, rented a one way U-Haul truck from Seattle to California, said goodbye to Microsoft, found a job in the San Francisco Bay area and got an admission offer to Carnegie Mellon University in Silicon Valley. The campus is located in NASA Research Park. If I was looking for an exciting change, I couldn't be more excited right now.

I'm writing this as of two weeks after the move. I drove the entire way within 24 hours. Everything I have is in storage and I'm hopping between hotels while working during the day and spending quality time with my girlfriend Abby in the evenings. The lifestyle reminds me of Europe: Not having a permanent place, but knowing that I'm treasuring life's passing moments more than I ever had during the routine periods. This is what George Leonard describes as "the inevitable spurts of progress and the fruits of accomplishment" and I'm sure to expect and accept that the next plateau beyond now offers less excitement and more hard work.

That brings me to the reason I'm writing today. The book "Mastery" by George Leonard, although written in a very simple literature form void of any fancy language -- kind of like my blog -- has changed my life. Since I read it 4 years ago, upon graduation and while hunting for my first career gig, it has transformed my way of thinking about life. It has made me realize truly what it means to pursue challenges instead of goals and rewards. It has inspired me to think of boredom, what he calls the plateau, as a time for pushing oneself and learning, so that the next "spurt of progress" is larger and more significant. Ambitious individuals sometimes wait around, like Neo in The Matrix, to suddenly be discovered and be told what their life mission is. I have learned that the knowledge is out there, but you are your only mentor and self-discipline is your only weapon. When the sea is calm, you should be preparing to master the next storm.

One of the key factors in my quest for sustained personal growth is keeping track of the best books recommended to me, using a spreadsheet. Doing so assures me that one day I will gain, in a short and contextually relevant period of time, what the author and thousands of readers have come to discover and treasure by consensus. Recommendations and reviews, such as those found on Amazon, are the best ways to find these books. I have found a better source though: University faculty recommendations, as well as high reviews and peer recommendations.

I'm going to read the following books sometime this year while working and going to graduate school. See if you are also interested:

  1. First things first (Stephen R. Covey)
    How to look at and organize your time totally differently.
    Carnegie Mellon University recommendation

  2. Leadership and self-deception: getting out of the box (Arbinger Institute)
    A novel-style life-changing book on how we view others, from inside our self-deceiving box, and how that impacts our ability to lead them
    Carnegie Mellon University recommendation

  3. Here comes everybody: the power of organizing without organizations (Clay Shirkey)
    According to the Publisher Weekly, the author contextualizes the digital networking age with philosophical, sociological, economical and statistical theories, and points to its major successes and failures. According to Ray Ozzie (Microsoft Chief Software Architect), the author's pattern-matching skills are second-to-none.
    Carnegie Mellon University recommendation

  4. The Master and Margarita (Mikhail Bulgakov)
    A banned Soviet-era book about protesting for freedom in the face of interrogation, fear, and terror. I'm interested in this book now, because the current affairs of my homeland, Iran, is a repetition of this history.
    Recommended a few years ago by my friend, Natasha

  5. One hundred years of solitude (Gabriel Garcia Marquez)
    A brilliant Latin American literature of love and loss that presents some contemporary history of that part of the world in the form of a mysterious fantasy. I enjoy history, both in real and fantasy form. I've also always held recommendations from this friend highly. Those are my motivations for wanting to read this book.
    Recommended a few years ago by my friend, Zavosh

Friday, July 17, 2009

C# technical interview algorithm question: Print 32-bit Integers with only 7 bits on

In a recent interview, the engineer at the other side of the table asked me to write C# code that would print out all 32-bit Integers that have only 7 bits turned on. I don't consider this a great interview question, because it doesn't measure most things, yet it strongly measures your ability to write recursive method signatures. How many times have you ever had to write complex recursive methods in your last job? When I interview people, I ask them algorithm questions they're very likely to use.

In case you're wondering, I did pass, but my whiteboard code wasn't as clean as the following.

Nevertheless, here's the source-code just in case it helps anyone prepare for an interview. Do your own validation. It spits out the answer but it might not have certain memory optimizations that someone with a C++ background might look for. For one thing, I'm passing a lot of arguments by copying. If they do insist on optimizations and they only give you half an hour, you probably don't wanna work for them anyway:


using System;

namespace PracticeApps.PracticeConsoleApps
{
class IntegerWithSevenBitsOn
{
static void Main(string[] args)
{
PrintIntegersWithSevenBitsOn();
}

// Prints all Integers that have only 7 bits on
static public void PrintIntegersWithSevenBitsOn()
{
PrintIntegersWithSevenBitsOn(0, 32, 1, 7);
}

// Helper to Print all ints with given # bits on
// number: The number that is modified recursively
// remainingSpots: Unassigned bit count in number
// mask: Helps flip a certain bit on the number
// unusedOnBits: ON-bit count yet to be placed
static private void PrintIntegersWithSevenBitsOn(
uint number,
int remainingSpots,
uint mask,
int unusedOnBits)
{
// Base case: No spots left to fill
if (0 == remainingSpots)
{
Console.Out.WriteLine(
Convert.ToString(number, 2));
}
// Recursive case
else
{
// As many remaining spots as ON-bits?
// Then place all of them recursively.
if (remainingSpots == unusedOnBits)
{
PrintIntegersWithSevenBitsOn(
number | mask,
remainingSpots - 1,
mask << 1,
unusedOnBits - 1);
}
// More spots than available ON-bits
else
{
// Use a Zero for the current spot
PrintIntegersWithSevenBitsOn(
number,
remainingSpots - 1,
mask << 1,
unusedOnBits);

// If available, use an ON-bit
if (unusedOnBits > 0)
{
PrintIntegersWithSevenBitsOn(
number | mask,
remainingSpots - 1,
mask << 1,
unusedOnBits - 1);
}
}
}
}
}
}

Thursday, July 16, 2009

The journey of a lifetime

On July 15th, 2008, exactly one year ago, I was sitting in a plane headed for Amsterdam. I bought the ticket overnight and made the decision to go to Europe.

Santorini Island, Greece
I had been working on a start-up idea for about 6 months. I had resigned from my job half way into it. The product wasn't coming together and I was running solo. I looked at my runway: My savings were quickly running out, and the hopes and dreams with them. I knew failure was imminent, but I decided to turn it into a different kind of victory. I decided to let go of everyone and everything: People filling me with negative emotions, fear of having to start over, and the terror of not living within identity constraints.

I took the remaining of my savings, filled a backpack and bought the cheapest one way ticket to Europe that I could find. I was ready to see the world before I was too old to explore. I wanted to live today without knowing my destination tomorrow.

I backpacked 22 countries.

My only companion from home was a used Lonely Planet book. I found new companions along the way. A handwritten journal remains from that trip that I may compile into this blog one day.

I travelled from Seattle, WA to Toronto, Canada where I caught my flight to Amsterdam, Netherlands. Then I travelled by train to Bruges, Belgium, followed by Brussels. From there I went to Berlin, Germany and Prague, Czech Republic. I went again by train to Vienna, Austria and by bus to Bratislava, Slovakia. Next, I stopped in Ljubljana, Slovenia, and then Zagreb, Croatia. I went to the beautiful coast of Split. I reached the beloved Mostar, Bosnia and Hercegovina by bus and also spent time in Sarajevo. Another bus took me to Belgrade, Serbia. I headed for Bucuresti, Brasov and Transylvania in Romania after that.

I slept in the train to Budapest, Hungary and took another train to Krakow, Poland. I visited Auschwitz and Birkenau.

Amin standing in front of a tank in Kiev, Ukraine on its independence day
A long train trip to Lvov and Kiev in Ukraine was followed by another trip back to Bucuresti, where I connected to another train to Sofia, Bulgaria. Athens, Greece was next, and then the islands of Santorini and Crete by ferry. When I returned to Athens, I headed for the port of Patras where I took a ship to Bari, Italy. I crossed the country to Napoli (Naples), and visited Pompeii, Sorrento and Amalfi Coast. My stay in Rome was followed by a visit to the Vatican City, then Firenze (Florence) and Milan. The scenic train ride to Interlaken, Switzerland and a short stop in Iseltwald helped me find my peace. A night ride from Geneva to Paris, France and a long stop in Barcelona, Spain were followed by a flight to London, England. Dream cities.

Edinburgh
To escape the expensive stay, I took a bus to Edinburgh, Scotland where I said my last goodbye to Europe. I went back to London where I got on my final plane to Toronto, Canada before starting a completely new life.

You will not be surprised if I tell you that 12 years ago this day, I had just gotten off a plane from Amsterdam to Toronto, having travelled across the Atlantic to start a new life away from my birthplace.

A simple itinerary will not tell you what it feels like to backpack for 80 days, say goodbye to your homeland permanently, or start anew. But after all these experiences, I am a changed man. I rewrote every aspect of my life when I returned: personal and career, short- and long-term.

New beginnings are easier on those who have experienced many endings. You find your place in the world. You realize that as long as you're alive you cannot possibly fail, unless you quit.