Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
To check if a given sequence is arithmetic, just check that the difference between every two consecutive elements is the same.
If and only if a set of numbers can make an arithmetic sequence, then its sorted version makes an arithmetic sequence. So to check a set of numbers, sort it, and check if that sequence is arithmetic.
For each query, get the corresponding set of numbers which will be the sub-array represented by the query, sort it, and check if the result sequence is arithmetic.