Light all the bulbs — Puzzle for Interview rounds

Question :

Consider a circle with 2014 light bulbs and only 2 of them are on and the rest are off. Anyone can choose any of the bulbs and change the state of the neighboring bulbs. The task is to find if we can switch all the 2014 light bulbs on ?

Solution :

Yes, it is possible to get all the light bulbs ON.

  • Firstly label all the 2014 light bulbs from B-1 to B-2014(in sequence).
  • As the positions of the light bulbs in the ON state are not mentioned in the problem statement.
  • So, consider that those 2 bulbs are adjacent to each other and are labeled B-1 and B-2.
  • Therefore, bulbs labeled from B-3 to B-2014 are initially in the OFF state and all the bulbs in the OFF state are adjacent to each other.

Follow the steps below to solve the given problem:

  1. Consider all the 2012 remaining bulbs in groups of 4.

2. In order to light up all the bulbs perform the following strategy:

  • The first group consists of bulbs B-3 to B-6.
  • Select the second bulb from the chosen group and change the state of adjacent bulbs.
  • Here, select bulb B-4 and change the state of bulbs B-3 and B-5 from the OFF state to the ON state.
  • The second step is to select a third bulb from the chosen group and change the state of its adjacent bulbs.
  • Here, select the bulb B-5 and change the state of bulbs B-4 and B-6 from OFF to ON.

3. Similarly, the above process can be repeated for a total of 503 groups(consisting of 4 light bulbs each) and all the given 2014 light bulbs can lighten up.

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

HTTP Request in JetBrains IDEs

Why vertical slice architecture is better-if you know these few things

Why I Think Python Is the Perfect Programming Language for Beginners

Migration from Windows to Linux

A screenshot of my current configuration of Arch Linux with Plasma

DevOps Introduction, Lifecycle, and Evolution

An Opinionated Guide to React Folder Structure and File Naming

Methods in C#

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

Dynamic Programming

GREEDY ALGORITHMS FOR DUMMIES BY A DUMMY

Leetcode 290. Word Pattern

Ratio of Boys and Girls Puzzle