Problem Statement
You have:
n sticks, each initially colored.
m painters, each performing an operation to paint a specified range of sticks with a new color.
Each operation is defined by three integers:
l: The starting index of the range to paint.
r: The ending index of the range to paint.
color: The color with which to paint the sticks in the range [l, r].
The goal is to determine the final color of all the sticks after all operations have been applied.
Example
Given:
n = 5 sticks with initial colors [1, 2, 3, 4, 5]
m = 3 operations:
Paint sticks in the range [1, 3] with color 10
Paint sticks in the range [0, 2] with color 20
Paint sticks in the range [1, 4] with color 15
The expected output is the final colors of the sticks after applying all operations.
[20, 15, 15, 15, 15]
Could someone tell me optimized approach for above question, I am unable to find out.
Not accepted strategies: