Why did you take computer science

Funny things happen in life everyday. In my campus interview, the guy who was taking my technical interview was very impressed with me, so he promptly asked me Why did you take up Computer Science. I have already said it in an earlier post that sometimes our mind works too fast for us to believe it. Same thing happened to me after he asked that question, I tried to recall why did I take up computer science and after analysing my entire life and all my encounters with computers prior to my joining my college, I could not find one motivating instance which drove me crazy about computers. The only answer I could manage to think was because on my counseling date everybody around me was filling the Computer Science of the same college and even my dad asked me to do so. But this would not impress my interviewer, I figured, so I transformed the answer into I was interested in computers from childhood Actually I first saw a computer when I was in class 8th and touched it in class 10th and in 11th and 12th only heard music and saw movies on it. I even said I was always into mathematics and solving programming problems alongwith finding efficient solutions. This was somewhat true but I was never a problem solving person, in fact I hated mathematics and always scored the least in it. Besides, I have a strict policy Conserve the brain :). I always used to say to my friends, ” .. yaar kuch bhi karunga par zindagi main computer science kabhi nhi padhunga.. kaisa boor subject hai yaar… aur sala bas computer k samne baithe rho …ch**tia ki tarah..“. But now I had to somehow make this guy to believe that I was born to be a programmer and that given a choice between a hottie and a laptop, I would die for a laptop. Funny na .. we find chameleons attractive and amazing in childhood but as we grow we develop into a chameleon ourselves. 🙂 I was laughing inside while I gave that answer but I am a nice actor, I put up a good show and even he believed that I was made for computers and programming was my religion. Mission Successful.

Hope the one who interviewed me never visits this post 🙂

Advertisements

My Principles in Life

It just crossed my mind today to collect some of the principles which I usually follow in my life. Well right now I don’t know how many 😛 but I have tried to bring to focus all those which are very important to me and have helped me become me.

  • No affairs/relationships in my own Colony, School, College and Work. This is the most important lesson which I was told by a very nice guy, and I understood the significance of this rule as soon as he said it to me. I was only 15 then, but surely had the senses to follow it and have followed it till date. Beautiful 🙂
  • Keep your patience, keep your cool, things will go your way.
    My guiding light throughout my academic success (if you say so) and many rough patches in life 🙂
  • (In Hindi) Saam, Daam, Dand, Bhed.
    The uber-famous quotation by Chanakya, it is really awesum and true even for today.
  • I didn’t have time to learn and I didn’t have much patience with what’s called the humanities, even though in the university there were humanities that you had to take. I tried my best to avoid somehow learning anything and working at it…. I have a limited intelligence and I use it in a particular direction.
    Heard it in a video about Richard P. Feynaman, and found it astonishingly valid for me 🙂
  • There is no avoiding of war, it can only be postponed to the adavntage of your enemy.
    Wish the leader of our country also had this divine insight
  • The only way to get smart is to play against the smarter opponent.
    An excerpt from an excellent movie, Revolver
  • A man can live a good life, be honourable, give to charity, but in the end, the number of people that come to his funeral is generally dependent on the weather.
    Another movie dialogue, if you think about it, it’s really amazing.
  • Whereof one cannot speak of, thereof one should be silent.
    A quote used by my professor, awesome man awesome thought.
  • When the money is gone, it’s time to move on.
  • “Don’t work hard in life for me or your mother, we aren’t going to ask you for anything, I have my reserves. It’ll just be nice for me to know that my son has done something significant in his life. That’s all I care for, that’s all I expect from you.”
    My dad to me ..

Interview Questions 5

1. Find all palindromes in a string.

2. Given two strings we have to calculate count of all common subsequences of 2 in 1st string.

3. Connect the leafs in a binary tree and return a reference to the first of the linked leafs. This would allow clients of this API to subsequently traverse the leafs. The API has a fLR flag indicating if the leafs should be connected from left-right (fLR = true) or from right-left (fLR = false).

Please implement the following API:

public Node ConnectLeafs(Node root, bool fLR)

Parameters:
Node root – a reference to the root of the tree
bool fLR – direction of leaf liking.

4. Write a function for the following scenario:
Given a number determine wether the number is sum of consecutive positive integers,if it is not return false else return true. conscutive integers can be from 2 to n

5. Given an n X n array with rows sorted and cols sorted, find the number of negative elements in most efficient way.

6. In our indexes, we have millions of URLs each of which has a link to some page contents, that is, URL->contents. Now, suppose a user types a query with wild cards *, which represent 0 or multiple occurrences of any characters, how do you build the indexes such that such a type of query can be executed efficiently by finding all corresponding URLs->contents efficiently. For example, given a query http://www.*o*ve*ou.com. You need to find iloveyou.com, itveabcu.com, etc.

7. Design a data structure with the following properties.
a. Insert in O(logn)
b. Delete in O(logn)
c. FindMin in O(logn)
d. FindMax in O(logn)

8. How will you find the number of all possible common subsequences between 2 given strings.

My First interview

It sounds very simple but when the first ever (technical) interview of your life is being taken by a Microsoft employee, things really get tensed. I considered myself a calm headed guy, certain friends might contradict, but I felt I could handle any sort of pressure until that interview. I went in the room very confident as I believed I was good at programming. The first question I got was about finding an element in a rotated sorted array. I don’t know why as soon as I saw my interviewer explain me the question, I started getting an intense feeling that “It’s all ruined”. I don’t know where it came from but it was strong and persistent throughout the time when I was trying to obtain a solution. My mind could think of a million reasons why I believed that I would ruin my interview but could not think of a very trivial solution to that problem. Anyhow, I managed an approach and told him half-heartedly. He simply asked to code and not explain the algorithm. I began coding, I had read somewhere that these guys see the way you write your code also, so I quickly wrote the code without any hesitation and showed it to him. He had not even completely read the code and wrote a test case for which it failed. Alas !!! I knew my approach was correct but I had messed up while coding. I was told just before entering the room that, “.. M$ guys love you if you write the code correct in the first attempt..” … imagine the state of my mind as soon as I found that the first code I wrote was wrong. I turned back and in remorse and repenting on my stupendous mistake I reviewed my code and after the first flaw I saw I knew that it was the culprit which caused my drown. I corrected it and then gave it back to the interviewer as if now the interview was just a formality for me. I think of myself at that point and really I could compare myself with a soldier fighting alone against the US army with a 3-NOT-3 rifle. And what follows, he went through my code again and wrote another test case where it broke. I don’t have enough knowledge of english language to express what went through my head when I dry ran that case on my code. But this time I don’t know what came to my mind and I thought to myself, “..abe ab kas to gayi hai hi.. hona to hai nhi.. to saale iske mu par code maaro.. abki galti nikal k dikha saale code main…” .. and that was me. I took the code, went over it, in one go I corrected all the mistakes I could se and in next view I tested it on 2-3 test cases which I had generated in my mind at the speed of light. Then I handed over the paper to him and rolled back on my chair. This time I had done it, he found no mistake in it and just said .. “ye chal jaega”. Now I was charged up because of the thought that had went past my mind and now I was like a free bird ready for anything. He posted another problem about the knight’s tour and before he could complete the problem I had written a recursive code for it and again tested it on my “lighting-speed” generated test cases, he asked to optimize it and I gave him the method which could be used to optimize it. Speechless, as he was, seeing the vibrant change in my attitude. Guys, really, when you have nothing to loose, whatever you do, you only gain. And though I was so distressed that after he relieved me, I came out with 1/10^100th the enthusiasm with which I had entered that room. I was sure that I had lost my chance and was waiting for the HR official to show me the way out. How fast my brain analyzed my interview and drew a zillion reasons of how I had screwed my interview was a thought I can never forget. And still I was there, waiting for the official denial, but a kindle of hope somewhere in the heart with a feeling that “..kya pata apni shakal achhi lagi ho sale ko.. aise nhi to waise hi pass kar de sala ..”, I stood there. And there she came out and called my name ….. and uttered the words “Avi, you have been scheduled for the next round of interview”.

Stay tuned to know what happened in that interview.

Naughtiness of Naughty :)

These are some of the interesting and hilarious ( see how both go together 😛 ) quotes which I have collected. I really appreciate the innovation behind such innovative comments .. njoi em

  • The ideal man is he who, in the midst of the greatest silence and solitude, finds the intensest activity, and in the midst of the intensest activity finds the silence and solitude of the desert.
  • I’m willing to admit that I may not always be right, but I am never wrong.
  • When a man steals your wife, there is no better revenge than to let him keep her.
  • After marriage, husband and wife become two sides of a coin; they just can’t face each other, but still they stay together
  • Woman inspires us to great things, and prevents us from achieving them.
  • I had some words with my wife, and she had some paragraphs with me.
  • Some people ask the secret of our long marriage. We take time to go to a restaurant two times a week. A little candlelight, dinner, soft music and dancing. She goes Tuesdays, I go Fridays. .. My personal fav. 😛
  • There’s a way of transferring funds that is even faster than electronic banking. It’s called marriage.
  • I’ve had bad luck with both my wives. The first one left me, and the second one didn’t.
  • Two secrets to keep your marriage brimming
    1. Whenever you’re wrong, admit it,
    2. Whenever you’re right, shut up.
  • All married women are not wives
  • The most effective way to remember your wife’s birthday is to forget it once…
  • You know what I did before I married? Anything I wanted to.
  • My wife and I were happy for twenty years. Then we met.
  • A good wife always forgives her husband when she’s wrong.
  • A man inserted an ‘ad’ in the classifieds: “Wife wanted”. Next day he received a hundred letters. They all said the same thing: “You can have mine.“
  • First Guy (proudly): “My wife’s an angel!”
    Second Guy: “You’re lucky, mine’s still alive.”
  • You can tell the ideals of a nation by its advertisements.
  • Conscience is a dog that does not stop us from passing but that we cannot prevent from barking.
  • A man can’t ride on your back unless it’s bent.
  • Divorce: The past tense of marriage.

Poems

कैसे कैसे उत्पाद

एक जगह बहुत भीड़ लगी थी

एक आदमी चिल्ला रहा था

कुछ बेचा जा रहा था

आवाज कुछ इस तरह आई

शरीर में स्फुर्ति न होने से परेशान हो भाई

थकान से टूटता है बदन

काम करने में नहीं लगता है मन

खुद से ही झुंझलाए हो

या किसी से लड़कर आए हो

तो हमारे पास है ये दवा

सभी परेशानियां कर देती है हवा

मैंने भीड़ को हटाया

सही जगह पर आया

मैंने कहा इतनी कीमती चीज

कहीं मंहगी तो नहीं है

वो बोला आपने भी ये क्या बात कही है

इतने सारे गुण सिर्फ दो रुपए में लीजिए

भाई साब दिलदार बीड़ी पीजिए

फुटकर हास्य कविताएँ –

1

पिताजी ने बेटे को बुलाया पास में बिठाया,

बोले आज राज की मैं बात ये बताऊंगा।

शादी तो है बरबादी मत करवाना बेटे,

तुमको किसी तरह मैं शादी से बचाऊंगा।

बेटा मुस्कुराया बोला ठीक फरमाया डैड,

मौका मिल गया तो मैं भी फर्ज ये निभाऊंगा।

शादी मत करवाना तुम कभी जिन्दगी में,

मैं भी अपने बच्चों को यही समझाऊंगा।

2. A very interesting and inspirational poem from the former PM Vajpayee ji.

हिन्दु तन मन हिन्दु जीवन रग रग हिन्दु मेरा परिचय॥

मै शंकर का वह क्रोधानल कर सकता जगती क्षार क्षार
डमरू की वह प्रलयध्वनि हूं जिसमे नचता भीषण संहार
रणचंडी की अतृप्त प्यास मै दुर्गा का उन्मत्त हास
मै यम की प्रलयंकर पुकार जलते मरघट का धुँवाधार
फिर अंतरतम की ज्वाला से जगती मे आग लगा दूं मै
यदि धधक उठे जल थल अंबर जड चेतन तो कैसा विस्मय
हिन्दु तन मन हिन्दु जीवन रग रग हिन्दु मेरा परिचय॥

मै आज पुरुष निर्भयता का वरदान लिये आया भूपर
पय पीकर सब मरते आए मै अमर हुवा लो विष पीकर
अधरोंकी प्यास बुझाई है मैने पीकर वह आग प्रखर
हो जाती दुनिया भस्मसात जिसको पल भर मे ही छूकर
भय से व्याकुल फिर दुनिया ने प्रारंभ किया मेरा पूजन
मै नर नारायण नीलकण्ठ बन गया न इसमे कुछ संशय
हिन्दु तन मन हिन्दु जीवन रग रग हिन्दु मेरा परिचय॥

मै अखिल विश्व का गुरु महान देता विद्या का अमर दान
मैने दिखलाया मुक्तिमार्ग मैने सिखलाया ब्रह्म ज्ञान
मेरे वेदों का ज्ञान अमर मेरे वेदों की ज्योति प्रखर
मानव के मन का अंधकार क्या कभी सामने सकठका सेहर
मेरा स्वर्णभ मे गेहर गेहेर सागर के जल मे चेहेर चेहेर
इस कोने से उस कोने तक कर सकता जगती सौरभ मै
हिन्दु तन मन हिन्दु जीवन रग रग हिन्दु मेरा परिचय॥

मै तेजःपुन्ज तम लीन जगत मे फैलाया मैने प्रकाश
जगती का रच करके विनाश कब चाहा है निज का विकास
शरणागत की रक्षा की है मैने अपना जीवन देकर
विश्वास नही यदि आता तो साक्षी है इतिहास अमर
यदि आज देहलि के खण्डहर सदियोंकी निद्रा से जगकर
गुंजार उठे उनके स्वर से हिन्दु की जय तो क्या विस्मय
हिन्दु तन मन हिन्दु जीवन रग रग हिन्दु मेरा परिचय॥

दुनिया के वीराने पथ पर जब जब नर ने खाई ठोकर
दो आँसू शेष बचा पाया जब जब मानव सब कुछ खोकर
मै आया तभि द्रवित होकर मै आया ज्ञान दीप लेकर
भूला भटका मानव पथ पर चल निकला सोते से जगकर
पथ के आवर्तोंसे थककर जो बैठ गया आधे पथ पर
उस नर को राह दिखाना ही मेरा सदैव का दृढनिश्चय
हिन्दु तन मन हिन्दु जीवन रग रग हिन्दु मेरा परिचय॥

मैने छाती का लहु पिला पाले विदेश के सुजित लाल
मुझको मानव मे भेद नही मेरा अन्तःस्थल वर विशाल
जग से ठुकराए लोगोंको लो मेरे घर का खुला द्वार
अपना सब कुछ हूं लुटा चुका पर अक्षय है धनागार
मेरा हीरा पाकर ज्योतित परकीयोंका वह राज मुकुट
यदि इन चरणों पर झुक जाए कल वह किरिट तो क्या विस्मय
हिन्दु तन मन हिन्दु जीवन रग रग हिन्दु मेरा परिचय॥

मै वीरपुत्र मेरि जननी के जगती मे जौहर अपार
अकबर के पुत्रोंसे पूछो क्या याद उन्हे मीना बझार
क्या याद उन्हे चित्तोड दुर्ग मे जलनेवाली आग प्रखर
जब हाय सहस्त्रो माताए तिल तिल कर जल कर हो गई अमर
वह बुझनेवाली आग नही रग रग मे उसे समाए हूं
यदि कभि अचानक फूट पडे विप्लव लेकर तो क्या विस्मय
हिन्दु तन मन हिन्दु जीवन रग रग हिन्दु मेरा परिचय॥

होकर स्वतन्त्र मैने कब चाहा है कर लूं सब को गुलाम
मैने तो सदा सिखाया है करना अपने मन को गुलाम
गोपाल राम के नामोंपर कब मैने अत्याचार किया
कब दुनिया को हिन्दु करने घर घर मे नरसंहार किया
कोई बतलाए काबुल मे जाकर कितनी मस्जिद तोडी
भूभाग नही शत शत मानव के हृदय जीतने का निश्चय
हिन्दु तन मन हिन्दु जीवन रग रग हिन्दु मेरा परिचय॥

मै एक बिन्दु परिपूर्ण सिन्धु है यह मेरा हिन्दु समाज
मेरा इसका संबन्ध अमर मै व्यक्ति और यह है समाज
इससे मैने पाया तन मन इससे मैने पाया जीवन
मेरा तो बस कर्तव्य यही कर दू सब कुछ इसके अर्पण
मै तो समाज की थाति हूं मै तो समाज का हूं सेवक
मै तो समष्टि के लिए व्यष्टि का कर सकता बलिदान अभय
हिन्दु तन मन हिन्दु जीवन रग रग हिन्दु मेरा परिचय॥

The same poem sung by him can be found here

Interview Questions 4

1.a) Design a data structure to store an arbitrarily large number
b) How will you use it to store two such number and add them.
c) Write down the class (code) for the data structure.

2.Given a file with a lot of words (10 million) find out the top 10% most frequently occuring words.

3. How will you convert an unsigned int into base -2.

4. There are two binary trees T1 and T2 which store character data, duplicates allowed.
How can I find whether T2 is a subtree of T1 ? .
T1 has millions of nodes and T2 has hundreds of nodes.

5. here are 3 sorted lists. We have to choose an element from each of the 3 lists such that, distance is minimum where distance is: |a-b| + |b-c| + |a-c|. ‘a’ being the element from the 1st list, ‘b’ from the second list and ‘c’ from the 3rd list.
Need to do it in O(n) time, ‘n’ being sum-total of length of the 3 lists

6. Suppose the positive integer n is odd. I write the numbers 1, 2, 3, …, 2n on the blackboard. Then I pick two numbers a, b, erase them and write, instead, |a-b|. Continue this practice till a single number remain on the board. Prove that an odd number will remain at the end.

7. Given an array with some repeating numbers. Like 12,6,5,12,6.
output should be printed as 12,12,6,6,5; i.e, all occurences of the no. should come together and nos. should come in the order given in the array.

%d bloggers like this: