Company: Autodesk_10april
Difficulty: medium
Query Processing and Triple Counting Problem Description You start with an empty integer array, numbers , and must process a sequence of queries against it. Each query takes one of two forms: "+x" : push the integer x onto the end of numbers . Duplicate values of x are allowed to coexist in numbers . "-x" : strip out every occurrence of the integer x currently sitting in numbers . After each query is applied, count how many triples (x, y, z) can be picked from the current contents of numbers such that both x - y and y - z equal a fixed value, diff . The three values making up a triple may be drawn from any positions in numbers , not necessarily consecutive ones. Return an array holding one count per query, in the same order the queries were processed. Examples Example 1: Input: queries = ["+4", "+5", "+6", "+4", "+3", "-4"], diff = 1 Output: [0, 0, 1, 2, 4, 0] Explanation: Applying queries[0] = "+4" pushes 4 onto numbers , giving numbers = [4] . No triple exists yet, so the count is 0.