Company: Visa_18_jan
Difficulty: medium
Coloring a Number Line Coloring a Number Line Problem Description Imagine you are given a number line represented by coordinates [0, length - 1] . Initially, all coordinates on the number line can be considered to have a color of 0 . You are given a list of queries that determines how to color coordinates along the line. Each query is in the following format: [coord, color] - color the coordinate coord with the given color . All existing colors are overwritten. After processing each query, you need to record the number of consecutive pairs of coordinates that currently have the same color (and the color is not 0 ). Your task is to return an array of length queries.length containing these recorded counts, one for each query. Example For length = 7 and queries = [[1, 2], [0, 2], [3, 5], [3, 2], [2, 2], [6, 1], [1, 3]] , the output should be [0, 1, 1, 1, 3, 3, 1] . Explanation Let's consider all queries: [1, 2] - color the coordinate 1 with color 2 . After this query, the number line beco