Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Can you solve the problem if all the numbers in the array were between minK and maxK inclusive?
Think of the inclusion-exclusion principle.
Divide the array into multiple subarrays such that each number in each subarray is between minK and maxK inclusive, solve the previous problem for each subarray, and sum all the answers.