Count Triples with Difference

Databricks coding interview problem: Maintain a dynamic multiset of integers with add/remove operations. After each step, report how many triples (x, y, z) in the multiset have equal consecutive differences (an arithmetic progression). Integers can be very large; removals always exist. Output the count after every operation. A classic interview question for a coding interview.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: