Find the length of the longest continuous subarray where the difference between its largest and smallest elements is less than K.
Asked in the DSA / BPS stage. Confirmed by OP ("yeah 2nd one").
Implement longest_subarray(nums, k). nums is a non-empty list of integers and k is a positive integer. Return an integer length. The condition is strict: max(window) - min(window) < k.
def longest_subarray(nums, k):