check(arr)
that takes a subarray arr
and determines if it can form an arithmetic sequence.arr
.diff
as (maxElement - minElement) / (arr.length - 1)
.diff
is not an integer, return false
.arr
into a hash set for efficient lookups.curr
as minElement + diff
.curr
is less than maxElement
, check if curr
is in the hash set. If not, return false
. Increment curr
by diff
.false
, return true
.check
to each subarray formed by l[i]
to r[i]
.