Given an array of integers nums and an integer limit, find the length of the longest contiguous subarray such that the difference between the maximum and minimum elements in that subarray is less than or equal to limit.
nums = [8, 2, 4, 7], limit = 42