Ninja and the Bulbs Challenge
Ninja owns an electronic shop and possesses 'N' bulbs. To verify the quality of the bulbs, Ninja performs a unique technique. After 'N' rounds of this process, bulbs that remain on are considered good quality. Your task is to determine the number of good quality bulbs for Ninja.
Explanation:
The technique is described as follows:
- In the first round, all bulbs are turned on.
- In the second round, every second bulb is turned off.
- In the third round, every third bulb is toggled (turned off if it's on, turned on if it's off).
- This process continues for 'N' rounds.
At the end of 'N' rounds, the bulbs that remain on are considered of good quality.
Example:
Input:
N = 4
Output:
2
Explanation:
Here's the status of the bulbs after each round:
- Round 1: All bulbs are on.
- Round 2: Bulbs 2 and 4 are turned off.
- Round 3: Bulb 3 is turned off.
- Round 4: Bulb 4 is turned on.
At the end, bulbs 1 and 4 are on, resulting in 2 good bulbs.
Constraints:
1 <= T <= 10
1 <= N <= 10^9
- Time limit: 1 sec
Determine the number of good quality bulbs remaining after 'N' rounds of a unique technique.
Start with all bulbs on in the first round
Toggle every 'i' bulb in 'i' round
Count the bulbs that remain on a...read more
Top Amazon SDE-2 interview questions & answers
Popular interview questions of SDE-2
Top HR questions asked in Amazon SDE-2
Reviews
Interviews
Salaries
Users/Month