Range Assignment Queries: Replace Array Subranges with a Given Value
Given an array and a list of queries, each represented as a tuple (L, R, K), return the final state of the array after applying all queries in order, where each query replaces all values at indices L through R (inclusive) with the value K. The problem has two subparts: (1) K is the same constant for all queries, and (2) K differs per query. Example: Array [1,2,3,4,5] with queries [(1,3,9),(2,4,7)] yields [1,9,7,7,7].
Asked at:
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Mid July, 2026
Mid-level
You have given an array and array of queries where each query is tuple i.e. (L, R, K). You have to return the final state of the array after apply all the queries. Each query represents: replace all values from L to R (both inclusive) to K. There are 2 subparts in this. 1. K is constant for all query. 2. K is different. Example: Array: [1, 2, 3, 4, 5] Queries: [(1, 3, 9), (2, 4, 7)]) Output: [1, 9, 7, 7, 7] Explanation: After `(1,3,9)`, the array becomes `[1, 9, 9, 9, 5]`. After `(2,4,7)`, positions 2 through 4 are overwritten, giving `[1, 9, 7, 7, 7]`.
Hello Interview Premium
Your account is free and you can post anonymously if you choose.