Wednesday, July 3, 2013

Interview: Can you put this deck of cards in order?

Can you put this deck of cards in order?


I wish I had this question in an interview before I read the article because I am not sure how I would have reacted to this question. I have a slight feeling that I may have just sorted the deck right there because it was something I used to enjoy doing when I was bored at some random place that had a deck of cards way back in the day.

On the other hand, I should have had enough experience to know there is something else that the interviewer is looking for. What order? Why do you want me to do that? Are you crazy? Ok, maybe not the last question but still probably better than just start sorting in silence.

Unfortunately, I read the description and it spoiled what I should not have known. What I like about this question is that this is actually very common type of request from "clients" in any industry. There are three main questions that needs to be asked: time, quality, and cost.

1. How much time do I have to sort the deck?
2. How well do you want the deck sorted?
3. How much are you willing to pay to have the deck sorted?

Most people's questions will probably revolve around quality. How do you want it sorted? So I would figure if you asked questions that answer the other two, you'd be ahead of the competition.

On revisiting this question, I think it would also be good to also demo certain sorts even if it is very simple to explain. For example while asking the interviewer (treated as a client) how they want it sorted, I would suggest some alternatives. "Perhaps you would like it sorted by suits" and separate the cards into 4 piles of the different suits. "Perhaps you prefer it sorted by odds and events" and separate the cards into 2 piles of evens and odds. When reaching a face card and ask "how do you want to treat face cards?" Maybe at the end show a card trick.

Reference:
11 Interview Questions You Wouldn't Think to Ask--But Should

Tuesday, July 2, 2013

Interview: Can you make a function that determines whether a string is a palindrome or not?

Can you make a function that determines whether a string is a palindrome or not?

I like this interview question. It is a simple question but gives the interviewer some leeway on how to manage the question. On the other hand, the interviewee also has some opportunity to show off without having to spend a lot of time.

The first part is knowing what palindrome means. If the interviewee knows, then they easily skip to the second part of finding the solution. My guess is that most people do not know what that means. In this scenario, I would imagine there are people who would guess what it meant and continued with a solution hoping that they guess correctly. In another, the interviewee may just admit that they do not know what the word means. The length of time and how you say it could say quite a bit about what kind of person you are. Eventually, the interviewer will provide the definition.

The next part is to explain how to create the function (not "yes, I can make a function..."). Depending on the job, the level of detail may be different. Basically there are two common solutions (in my limited world): 1. create another string in reverse order then compare if the two strings are the same, 2. compare each letter from start to end with the opposing letter from end to start.

That may be sufficient for most non-programming jobs. For programming jobs, interviewees are probably expected to be more elaborate. They can provide alternate solutions, improving their proposed solution (refactoring), compare different algorithms, etc.

Personally, I like this question as an interviewer in that there is a lot of information that you can get within a short period of time and most interviewees will be able to answer the question. Also, I found it surprising how many candidates are incapable of answering basic questions. For example, I had one candidate with a BS in Computer Science who couldn't explain a loop. Another example, I had to train a new hire who supposedly has been in the IT industry for several years and has several MCSE certifications who asked how to create an object from a class. (Sorry for the CS lingo... it basically translates to a carpenter not knowing how to use a hammer)


Reference:
11 Interview Questions You Wouldn't Think to Ask--But Should

Tuesday, June 4, 2013

Life: Randomness in terms of free will, destiny, and fate (Take 7 of infinite)

For me, solving randomness is the ultimate way to cut corners in life and perhaps the only way to "solve" life. Because the more I think about it, the more I need to know. At some point, my mind has to contain more atoms to understand a single atom thus it is an impossibility to solve life through brute force. The only alternative is to truly become one with the world which I'll leave for another topic which I also do not think is solvable via the conscious mind.

Back to randomness... I like using casino games to visualize the unknown and the known. The games typically have simple rules yet works with a finite set of known values. For example, a typical poker deck has 52 cards, 13 cards of 4 different suits. Once I shuffle the deck, there is a 1 in 52 chance I will guess the card on top correctly. And no matter how much I try to make a better educated guess, the known world already knows what the top card is.

So me guessing is like free-will. I use only a limited set of knowledge to figure out what the card is. Any gambler would also be exercising their free-will to determine the card for they could potentially choose any card. But the dealer who has seen the top card, he know longer has free-will to guess the card because he already knows it.

My choice is like fate. Through whatever psychological explanation of seeing a lot of a certain number or associated colors or the proximity of the full moon, there really was only one choice I would have made. In other words... if you knew exactly how my brain works, you would have known my answer before I knew my answer.

Likewise, the top card was fated to be at the top. The deck was shuffled precisely so that specific card would end up at the top even though it was not the intention of the dealer. Thus a machine that can watch the cards or calculate how the deck was shuffled, it had not free-will in knowing what the top card is. Also, the security guard watching the game on video in slow-motion also has no free-will because he now knows what the card is.

Although destiny is often used interchangeably with fate, I will use it as a predetermined result. In other words if I was destined to guess the card correctly, the top card is not known. The top card will be whatever card I guess. For this to work in reality, this would mean that the world was unraveled backwards like solving a problem backwards... except that I "live" it forwards.

Thus, I think the comparison between free-will, fate, and destiny do not have to be mutually exclusive. Each can co-exist in the same matter as I have described above.

This is important to me because I think this helps me understand about randomness, just something that fascinates me like infinite, duality of choice, nothing, irrational and complex numbers. Each with their own characteristics of existence yet not something fully understood (likely will never be). Unlike those, randomness does not truly exist (in my opinion).

The world is what it is. If the world went back in time, I would not even know. Just like how the "actors" in a video do not know when you rewind a video or fast forward or put into slow-motion. If randomness truly existed, the ending would change each time you replayed the video. The top card could potentially change each time you went back in time.

In a small scale, randomness is our mind's way to simplify a problem through statistics. If I flip a coin, it is 50/50 chance that it lands heads or tails. The coin landing on its side is negligible or even irrelevant because you'd just re-toss the coin anyways. Worrying about how hard you flicked the coin, how high it went, and etc., it is much easier just to say it would be one over the other.

On a grander scheme, we gamble on many things all the time in life except the odds of it failing is very, very small. "If I go at this speed, I will have better chance of hitting a green light." "I forgot my badge, what are the odds that guard happened to step away when I get there." What are the odds you get a flat tire? What are the odds that you get hit by a drunk driver? If I deal out 52 cards randomly to 52 people, each person has a 1 in 52 chance to have the ace of spades but yet someone is guaranteed to have the ace of spades.

Although life is about decreasing risk at an effective rate, there are times when we want randomness to be as "chaotic" as possible, like generating security keys, simulating a casino game, or possibly just to make things "fair" (like the lottery). How does someone go about making things random?

If the problem of randomness is about the limitations on the knowledge of the guesser, then randomizing a value is about making the environment as impossible for the guesser to "calculate" the answer at an effective rate. Because true randomness is impossible, effective rate is important to how close to true randomness the application needs to be. For example, if a weighted coin has 75% to land on head and you win 100 points each time you guess correctly, you will likely always choose heads. Even if it cost 1 point to play, you will continue to guess heads. But if I make use a "fair" coin, then you will likely choose to not play at all because the probability is that you will lose each game.

By observing all the randomness around us and trying to make as much sense as possible, I wonder if it is possible for me to guess randomly. People have a tendency to start with heads or tails. People have a set of numbers they tend to use for "random" purposes. Even for things we never would had to choose between, we still have tendencies. It could be the constant use of certain words, or constant visuals of a certain numbers, or an infinite of things that make us tick that predetermines our supposedly random choices. In other words, ultimately, if I were starving and there were two plates of food equidistant from me. Which plate would I go to first? Or will I just starve to death because I cannot make a logic choice?

Thus, at some point each of us has a moment of insanity to break out of an unsolvable problem or dilemma however small it may be. Hope that will make sense to me some time in the future.

Reference:
http://xkcd.com/221/