Skip to main content

Posts

Showing posts from April, 2014

Two sticks and matchbox, measure exactly 45 minutes by burning these sticks

Question: You have two sticks and matchbox. Each stick takes exactly an hour to burn from one end to the other. The sticks are not identical and do not burn at a constant rate. As a result, two equal lengths of the stick would not necessarily burn in the same amount of time.  How would you measure exactly 45 minutes by burning these sticks?

Answer: This puzzle used to be asked in Wall Street interviews long time ago. It is very rare for this question to be asked now but it is a very good question to help you think a little outside the normal thought process.

The answer is really simple. Since the sticks do not burn at a constant rate, we can not use the length of the stick as any sort of measurement of time. If we light a stick, it takes 60 minutes to burn completely. What if we light the stick from both sides? It will take exactly half the original time, i.e. 30 minutes to burn completely.

0 minutes – Light stick 1 on both sides and stick 2 on one side.
30 minutes – Stick…

Aptitude Question - what is the proportion of boys to girls in the country?

Question: In a country where everyone wants a boy, each family continues having babies till they have a boy. After some time, what is the proportion of boys to girls in the country? (Assuming probability of having a boy or a girl is the same)

Answer: This is a very simple probability question in a software interview. This question might be a little old to be ever asked again but it is a good warm up.

Assume there are C number of couples so there would be C boys. The number of girls can be calculated by the following method.
Number of girls = 0*(Probability of 0 girls) + 1*(Probability of 1 girl) + 2*(Probability of 2 girls) + …
Number of girls = 0*(C*1/2) + 1*(C*1/2*1/2) + 2*(C*1/2*1/2*1/2) + …
Number of girls = 0 + C/4 + 2*C/8 + 3*C/16 + …
Number of girls = C
(using mathematical formulas; it becomes apparent if you just sum up the first 4-5 terms)
Thus the proportion of boys to girls is 1 : 1.

Finding the sub-array with the largest sum.

Question: You are given an array with integers (both positive and negative) in any random order. Find the sub-array with the largest sum.

Answer: This is an all-time favorite software interview question. The best way to solve this puzzle is to use Kadane’s algorithm which runs in O(n) time. The idea is to keep scanning through the array and calculating the maximum sub-array that ends at every position. The sub-array will either contain a range of numbers if the array has intermixed positive and negative values, or it will contain the least negative value if the array has only negative values. Here’s some code to illustrate.
void maxSumSubArray( int *array, int len, int *start, int *end, int *maxSum ) { int maxSumSoFar = -2147483648; int curSum = 0; int a = b = s = i = 0; for( i = 0; i < len; i++ ) { curSum += array[i]; if ( curSum > maxSumSoFar ) { maxSumSoFar = curSum; a = s; b = i; } if(…

Reverse a Linked-list. Write code in C.

Question : Reverse a Linked-list. Write code in C.

Answer: There are multiple ways to go about this. Let’s first look at a recursive solution.
Node * reverse( Node * ptr , Node * previous) { Node * temp; if(ptr->next == NULL) { ptr->next = previous; return ptr; } else { temp = reverse(ptr->next, ptr); ptr->next = previous; return temp; } } reversedHead = reverse(head, NULL);
Now for a non-recursive solution.
Node * reverse( Node * ptr ) { Node * temp; Node * previous = NULL; while(ptr != NULL) { temp = ptr->next; ptr->next = previous; previous = ptr; ptr = temp; } return previous; }
If anyone has any modifications or a better methods, please post it up. Comments are always welcome.

TCS Aptitude test, Placement Questions with Solution

1) If log 0.317=0.3332 and log 0.318=0.3364 then find log 0.319 ?
Sol: log 0.317=0.3332 and log 0.318=0.3364, then
log 0.319=log0.318+(log0.318-log0.317) = 0.3396

2) A box of 150 packets consists of 1kg packets and 2kg packets. Total weight of box is 264kg. How many 2kg packets are there ?
Sol: x= 2 kg Packs
y= 1 kg packs
x + y = 150     .......... Eqn 1
2x + y = 264   .......... Eqn 2
Solve the Simultaneous equation; x = 114
so, y = 36
ANS :  Number of 2 kg Packs = 114.

3) My flight takes of at 2am from a place at 18N 10E and landed 10 Hrs later at a place with coordinates 36N70W. What is the local time when my plane landed?

Options: a)6:00 am b) 6:40am c) 7:40 d) 7:00 e) 8:00
Sol: The destination place is 80 degree west to the starting place. Hence the time difference between these two places is 5 hour 20 min. (=24hr*80/360).
When the flight landed, the time at the starting place is 12 noon (2 AM + 10 hours).
Hence, the time at the destination place is 12 noon - 5:20 hours = 6: 40 AM

Upcoming Exams Dates and Details- Government, Bank..

Upcoming Notifications:

Banks :

Recruitment Board Post nameSBIClerksSBI Associate BankPO
UPSC :

Post DateExam NameLast Date 17/05/2014Civil Services (Preliminary) Exam 201416/06/201417/05/2014Indian Forest Services (Preliminary) Exam 201416/06/201421/06/2014NDA & NA Exam (II) 201421/07/201419/07/2014CDS Exam(II) 201418/08/2014
SSC :

Post DateExam NameLast Date24/05/2014Stenographer (Gr C&D) Exam 201420/06/201419/07/2014Combined Higher Secondary (10+2) Exam 201415/08/201409/08/2014Junior Translator (CSOLS)/Jr Hindi Translator Exam 201405/09/2014
Indian Army :
Notification DateName of The CourseTentative Course of Commencement.


TNPSC :
Post DateExam NameTentative Vacancies1st Week of March 2014  (To be Notified Later)Group VI Examination (Forest Apprentice)263rd Week of March 2014  (To be Notified Later)Assistant Works Manager42nd Week of April 2014  (To be Notified Later)Combined Civil Services Exam-II (Interview Posts) [Group-II Services].4th Week of April 2014Statistical Inspector22nd …

Head First Java 2nd Edition - Popular Book

Rs. 625 This is a book that is tailored for Java novices. Ideal for those who are interested in learning Java but have been put off by the complexities of learning the language, Head First Java explores a new way of teaching the same.

Head First Java is aimed at people who are complete novices when it comes to programming with the language, and the book makes the learning experience fun - one that?s filled with innovative and novel measures.

If you?re not a fan of wracking your brain with dull theoretical concepts that put you to sleep, Head First Java can be a welcome addition to your shelf.

The book starts from the fundamentals and progresses to extremely advanced levels, employing an easy-to-learn approach throughout. From distributed programming with RMI and network sockets, object oriented design, and object properties and methods, to graphical user interfaces, Java archives, network connectivity and Java 5.0, the book explores every facet of the programming lan…

Android device emulator shortcuts

Escape - Back button
Home - Home button
F2, PageUp - Menu button
Shift-F2, PageDown - Start button
F3 - Call/Dial button
F4 - Hangup/EndCall button
F5 - Search button
F7 - Power button
Ctrl-F3, Ctrl-KEYPAD_5 - Camera button
Ctrl-F5, KEYPAD_PLUS - Volume up button
Ctrl-F6, KEYPAD_MINUS - Volume down button
KEYPAD_5 DPAD - center
KEYPAD_4, KEYPAD_6 DPAD left, DPAD - right
KEYPAD_8, KEYPAD_2 DPAD up, DPAD - down
F8 - Toggle cell network on/off
F9 - Toggle code profiling (when -trace set)
Alt-ENTER - Toggle fullscreen mode
Ctrl-T Toggle - trackball mode
Ctrl-F11, - KEYPAD_7
Ctrl-F12, - KEYPAD_9