Your question is Array Repeat With Complexity. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Avensys Consulting UK may process ordered numeric sequences where the earliest repeated value must be identified quickly. Implement find_first_repeated for two scenarios and return the number whose second occurrence appears first.
nums may contain any integers, and the input must not be modified. Minimize time complexity.constant_space is True, nums has length n, contains integers in the range 1 through n, and may be modified. Use the array itself to achieve constant auxiliary space.Return None if no value is repeated. The function must return the first repeated value according to scan order. For example, in [4, 2, 5, 4, 2], return 4 because its second occurrence is encountered first.
nums, a list of integers, and constant_space, a Boolean.None.constant_space is False, preserve nums and use expected O(n) time.constant_space is True, mutation is allowed and extra space must be O(1).def find_first_repeated(nums, constant_space):