← Questions

Count arithmetic triples in a multiset under add and remove queries

0
DatabricksCodingLast asked Aug 2024

Start with an empty multiset and a fixed difference d. Each query either adds one copy of x or removes every copy of x. After each query, report how many triples of elements (counting copies separately) can be ordered as x, x + d, x + 2d. Keep a count per value and update the running total by only the triples that the changed value takes part in, instead of recounting.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding