Count Open Lockers

Posted in Puzzles on June 8, 2008 by gyri

Suppose you are in a hallway lined with 100 closed lockers. You begin by opening all 100 lockers. Next, you close every second locker. Then you go to every third locker and close it if it is open or open it if it is closed (call this toggling the locker). You continue toggling every nth locker on pass number n. After your hundredth pass of the hallway, in which you toggle only locker number 100, how many lockers are open?

In a hall with k lockers, how many lockers remain open after pass k?

Weighing problem

Posted in Computer Science, Logical, Programmatic, Puzzles on June 5, 2008 by Naresh Kumar

You have an object that weighs between 1KG and 100 KG (only +ve integer value).

What would be the minimum number of weighing stones you would require to weigh this object correctly?

(You can pick weighing stones of any denomination and you can pick multiple weighing stones of the same denomination)

Delete a node in the linked list

Posted in Computer Science on June 5, 2008 by Naresh Kumar

Given a node in the linked list. What is the optimal way of deleting it?

Find the missing element

Posted in Computer Science, Logical, Programmatic, Puzzles on April 23, 2008 by Naresh Kumar

Find the missing number in an array of ‘n’ unsorted numbers (0 to n-1).

Shift elements in an array

Posted in Computer Science, Programmatic on April 11, 2008 by Naresh Kumar

Circularly shift an array of “n” elements by “k” positions in O(n) time.

Courtesy: Rajesh

Message Passing

Posted in Computer Science, Logical, Puzzles on April 10, 2008 by Naresh Kumar

A has to pass a message to B by putting it in a box. Box has to be sent by a messenger and the messenger is not trust worthy. So the box has to be locked.

Both A & B has as many locks as recquired. But keys are not shared (i.e., if a lock is possessed by A, the key of the same will only be with A and B wouldnot have it). More than one lock can be put to a box.

Device a mechanism to safely send the message from A to B.

Reusability

Posted in Computer Science, Logical with tags on March 21, 2008 by srawon

I have been asked this question in an interview recently.

You have a method that takes an array of integers and returns the largest element. How will you use this method to find the least element in the array?

A little offbeat :)

Posted in General with tags on March 20, 2008 by Sreelu

Pick the odd number out

1    one-third

2    thirteen

3    thirty-one

Find an optimal solution for…

Posted in Computer Science, Programmatic on March 19, 2008 by srawon

You are given 2 strings s1 and s2. You are required to determine how many times each of the characters of s1 occur in s2. Both s1 and s2 contain lowercase characters from the English alphabet.

Pirates of the Caribbean

Posted in Logical on March 19, 2008 by kris

Five pirates on an island have one hundred gold coins to split among themselves. They divide the loot as follows: The senior pirate proposes a division, and everyone votes on it. Provided at least half the pirates vote for the proposal, they split the coins that way. If not, they kill the senior pirate and start over. The most senior (surviving) pirate proposes his own division plan, and they vote by the same rules and either divide the loot or kill the senior pirate, as the case may be. The process continues until one plan is accepted. Suppose you are the senior pirate. What division do you propose? (The pirates are all extremely logical and greedy, and all want to live.)