Implement a traffic-light UI with JS
Company: Salesforce
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates front-end web development competencies, including DOM manipulation, CSS-driven UI state, JavaScript timing and asynchronous state management for interactive components.
Constraints
- 1 <= red_duration, green_duration, yellow_duration <= 10^9
- 0 <= len(queries) <= 2 * 10^5
- 0 <= queries[i] <= 10^18
Examples
Input: (5, 4, 2, [0, 4, 5, 8, 9, 10, 11, 12, 20])
Expected Output: ['red', 'red', 'green', 'green', 'yellow', 'yellow', 'red', 'red', 'yellow']
Explanation: The cycle length is 11. Times 0 and 4 are in red, 5 and 8 are in green, 9 and 10 are in yellow, then the cycle repeats at 11.
Input: (1, 1, 1, [0, 1, 2, 3, 4, 5])
Expected Output: ['red', 'green', 'yellow', 'red', 'green', 'yellow']
Explanation: Each light lasts exactly 1 millisecond, so the pattern repeats every 3 milliseconds.
Input: (3, 2, 1, [])
Expected Output: []
Explanation: With no queries, the result is an empty list.