Showing posts with label Interview. Show all posts
Showing posts with label Interview. Show all posts

Saturday, July 16, 2011

Confessions of an Ebook Pirate

Today I found this article, titled "Confessions of a Book Pirate". Its an email interview with a bibliophile who is also a book pirate. The person in question has a name "The Real Caterpillar" in one of the many book sharing communities that he participates. He makes quite a few points which seemed logical and worth noting. The article is a definite recommend from me for anybody who loves books and is aware of ebooks and piracy.

However, some of the arguments seem feeble. Like "I would probably still grab a book if I stumbled across the file and thought it might interest me – or if I wanted to check it out before buying a paper copy". Well both of these can be very well accomplished in Google Books (partial book) or in the local bookstore (full book).

Personally, some of my interests fall into pretty much the tail end of the curve; and often finding books on some of these topics are quite difficult. Sometimes the books themselves are out of print. But I guess the ebook industry is moving towards the correct direction. With ebook readers flooding the market and big players like amazon coming in, bibliophiles like me are having a good time. Still it will take quite sometime till the entire spectrum is covered.

Thursday, April 21, 2011

Generate Palindrome by Appending Characters

I was recently asked this programming puzzle at an interview:
Given a string as input, construct the smallest length palindrome from that string by adding 0 or more characters at  the end of the string.
So for input "abb" it would be "abba" with only one character added at end; for "abcdaad" it would be "abcdaadcba" with three characters added to the end. Of course in the worst case all n-1 characters have to be added as in "abbc" and the best case is if the string is already a palindrome like "abcba".
This is what I wrote: (note that the first question was about checking a string for palindrome, so I kind of thought it would be cool to reuse that piece of isPalin() function that I had already written)


Coming back home it occurred to me that I could have made the code smaller by writing an strrev() function to reverse a string and checking for palindrome with a combination of strcmp() and strrev(). This would furthermore allow me to reverse the beginning non-palindrome part of the input string, which I could directly copy to the end of the newly created palindrome string using strcpy(). Then I came up with this:


Unfortunately it seems that the length of the code did not change much. Or in other words, my innovative idea was no so cool after all.

PS: it seems that there is some issue with the terminating NULL charracter ('\0') of C and PasteBin. Please go through the RAW source code.

Friday, February 18, 2011

Feynman's answers to Lateral Thinking puzzles

Late physicist Richard P. Feynman was well known for answering questions in a typical manner unique to him. Here are a few humorous takes on what he would have replied to the so called "lateral thinking" questions that are asked routinely at software company interviews these days.

Here are two examples of the quirky answers that he might have given to these trick questions:
What is amusing is that all the answers are all valid but differs from what the interviewer wants to hear. So the interviewer can neither refute the answers nor be satisfied by them.

A reader gave me this link in which Feynman is answering the question "Why do magnets attract or repel each other?". This is also a classic example of the fact that any fool can ask questions which the wisest man cannot answer.