Min Elevator Trips — Puzzle for Interview rounds

Question :

You are at the bottom of the elevator shaft of a 100 story building.

You see 21 wires labelled 1 2 3 … 21.

The wires go up to the 100th floor where the ends are labelled A B C … U, but you don’t know how they correspond to the ends at the bottom.

You have a battery, a light bulb, and many small wires.

What is the minimum number of trips required to find out the pairing between the letters and the numbers?

Note that connecting the small wires to form a wire 21 floor long is not an option.

Solution :

Note that your battery, light bulb and small wires are basically a connection tester, and that “connected” is an equivalence relation.

At the bottom, leave 1 unconnected, connect 2 and 3 to each other, connect 4–6 to each other, 7–10, etc, so that we have “equivalence classes” of connectedness of sizes 1, 2, 3, 4, 5 and 6.

Now make a trip to the top, and figure out which letters are connected to nothing else, to one other letter, to two others, etc, until you have figured out the equivalence classes.

Now connect the first letters from each equivalence class (there are 6 of them) in a new equivalence class, the second from each (5 of them) in another, etc. Go to the bottom, remove the original connections, and figure out the new equivalence classes in a similar manner.

We now know from the first set of classes what groups of n letters (for n=1 to 6) at the top correspond to what groups of n numbers at the bottom. From the second set of classes we now know which letters and numbers were the “first” in their original classes, which were the “second,” etc, so we have the complete pairing.

This solution works cleanly for any triangular number of wires, but can be easily adapted to work for all natural numbers greater than 2.

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.

--

--

--

Upskilling students for tech placements!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Accelerating the debugging process by using a hybrid environment

4 things (your are likely ignoring) to teach SaaS customers now

How to Set up GoDaddy Domain with Vercel

Number of Pairs with Given Sum

Kubernetes: Idea That Took The Center Stage

First World Problem for Developers: Reading Our Own Code

Customize Auth0 Universal Login Texts

Microservices with Spring Cloud & Docker

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Placewit

Placewit

Upskilling students for tech placements!

More from Medium

Cross the Bridge Puzzle

Monotonic Stack Problems

Reorder Data in Log Files

Leetcode Q392. Is Subsequence (Q322)