Grid Lights is a famous problem which has been asked in Machine Coding round of Frontend Interviews.
Build a grid of light cells where you can click on cells to activate them, turning them red. When all the cells are activated, all the cells will be deactivated one by one in the same order they were activated with an interval in between them.
Additionally, I have added another step to this where the grid cells are rendered based on user input (0s and 1s)
- Get user input for the grid row size.
- Prepare the grid component's input data, based on the user's input.
- Render the grid cells based on the input data.
- Add logic for activating cells when clicked.
- Once all the cells are activated, deactivate them one by one using setInterval.
Click here to view the demo.