Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Roy and LEDs problem solution

YASH PAL, 31 July 202411 February 2026
In this HackerEarth Roy and LEDs problem solution Its Diwali time and there are LED series lights everywhere. Little Roy got curious about how LED lights work. He noticed that in one single LED Bulb there are 3 LED lights, namely Red, Green, and Blue. The state of the bulb at any moment is the sum of Red, Green, and Blue LED lights.
The bulb works as follows:
Roy took out all the LEDs and found that Red LED stays ON for R seconds, Green LED stays ON for G seconds and Blue LED stays ON for B seconds. Similarly, they stay OFF for the same respective R, G, B number of seconds. (Initially, all the LEDs are OFF. See Sample Test Case Explanation for better understanding)
Roy has one query for you, given the total number of seconds T, find the number of seconds Red, Green, Blue, Yellow, Cyan, Magenta, White, Black(no light) lights are visible.
HackerEarth Roy and LEDs problem solution

HackerEarth Roy and LEDs problem solution.

def led():
T,R,G,B = map(int,raw_input().split())
red = [0]*1000001
green = [0]*1000001
blue = [0]*1000001
colors = [0]*8
r = 0
rp = 0
g = 0
gp = 0
b = 0
bp = 0
for i in xrange(T):
if i >= R + 2*R*r and i < 2*R + 2*R*r:
red[i] = 1
rp += 1
if rp%R == 0:
r += 1
if i >= G + 2*G*g and i < 2*G + 2*G*g:
green[i] = 1
gp += 1
if gp%G == 0:
g += 1
if i >= B + 2*B*b and i < 2*B + 2*B*b:
blue[i] = 1
bp += 1
if bp%B == 0:
b += 1
for i in xrange(T):
if red[i] == 1 and green[i] == 0 and blue[i] == 0: #red
colors[0] += 1
elif red[i] == 0 and green[i] == 1 and blue[i] == 0: #green
colors[1] += 1
elif red[i] == 0 and green[i] == 0 and blue[i] == 1: #blue
colors[2] += 1
elif red[i] == 1 and green[i] == 1 and blue[i] == 0: #yellow
colors[3] += 1
elif red[i] == 0 and green[i] == 1 and blue[i] == 1: #cyan
colors[4] += 1
elif red[i] == 1 and green[i] == 0 and blue[i] == 1: #magenta
colors[5] += 1
elif red[i] == 1 and green[i] == 1 and blue[i] == 1: #white
colors[6] += 1
else: #black
colors[7] += 1
print ' '.join(str(x) for x in colors)
led()
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes