Write complete code to find the longest consecutive substring in an array.
Asked in the Technical HR stage. Full working code required.
Implement longest_consecutive_substring(nums), where nums is an array of integers. Return the longest contiguous subarray in which each value is exactly one greater than the previous value. If multiple subarrays have the same maximum length, return the earliest one. Return an empty array for empty input.
Example: nums = [4, 5, 6, 2, 3, 4, 5] returns [2, 3, 4, 5].
Constraints: 0 <= len(nums) <= 10^4; values are integers.
def longest_consecutive_substring(nums):