## Interview Question

Software Engineer IV Interview

-Santa Clara, CA

# Two people are each stuck on their own island, connected by a ferryman with a lockable box. Each person has their own lock and key, but can't send the key along with the box. One person wants to send the other a diamond, but it must be placed into the box and locked or it will be stolen by the ferryman. How do you send the diamond without the ferryman stealing it?

Tags:abstract synonym flow charting

2

1) person A sends key only in a unlocked box to person B. 2) person B sends key only in a unlocked box to person A. 3) 3rd trip person A puts diamonds in the box snaps the lock their holding closed. (At this point owner of the lock can't open the lock. Ensure all contents are in the box before engaging lock.) 4) once the lock box arrives to person B, they can use the key provided on the trip before to open and stare at the contents, And realizes he can pay the ferryman to give him/her ride off the island. Then place a thank you note in the box and close with lock initially held by person B and which now person A has the key. Option B for #4 step) send a thank you note and lock with which the diamonds were so cleverly send to you sealed with. ;) *** Now follow up question would be, how to ensure the ferryman didn't copy the keys during the first transfer of keys? Answer) well, I guess you could have exchanged open locks and not the keys between the two people, and if he could copy a lock on a boat - the ferryman should be looking into more rewarding currier. But why do they care about diamonds when their stuck on an island, not stranded just stuck - pay the ferryman. There is always a man in the middle, know what to trust and what not to. Focusing on security when you may have bigger problems is useless.

Paresh on

1

Step 1: The person with the diamond, puts it in the box, locks it with his lock (Let's say Lock1). The ferryman takes it across. Step 2: Person 2 locks the box again with his lock (Lock2) Sends it back with the ferryman. Step 3 : Person 1 unlocks Lock1. Sends it back. Step 4 : Person 2 unlocks Lock 2 and retrieves the diamond.

Anonymous on

1

The upvoted answer has a flaw. The rules state you cannot send your key in the box. Here's how I'd solve it. 1) Person A sends a note in the box unlocked saying send me your lock open. If writing materials are not available, they can send a verbal message with the ferryman. 2) Person B places their lock inside the unlocked box and sends it back 3) Person A places the diamond in the box and locks it with Person B's lock 4) Person B receives the locked box, opens it with their key.

Zarren Spry on

0

Let's say person B has the diamond, and person A has the box. person A sends the empty box with the unlocked lock in it. person B opens the box, takes out the lock, puts the diamond in, locks the box, and sends it back to person A who unlocks the box and now has the diamond.

Anonymous on

0

You ride with the ferryman.

Bobbie G on

0

There’s only one fully secure answer. You can’t place your lock on the unlocked box and hope it gets there. You have to follow the pattern of lock, lock, unlock, unlock. I think Anonymous answered it perfectly. There is no other fully secure solution.

Tomas on

0

Paresh on

0

This isn't meant to be an open-ended question. It's a test of your problem-solving abilities, and a good interviewer will say that up front. In technical interviews these days, interviewers want to know how you would attempt to solve problems you haven't seen before, or that don't seem to have a clear and obvious answer. For example, in this problem an important piece of information that wasn't presented is that the box can be locked with more than one lock. Once you realize that it's a much easier problem. If you haven't interviewed outside of your present company for a long time you have to remember that you're meeting a lot of people who know nothing about you other than what's on your resumé and are counting on the interview to determine whether or not you can do what your resumé says you can do. Be prepared to answer questions that show you can implement an algorithm given to you, or that you understand basic data structures and programming techniques. I also recommend the book "How to Land The Tech Job You Love", especially if you haven't done any interviewing in some time.

Scott on

2

This is an analog version, if you like, of public key encryption.

Anonymous on

0