Pergunta de entrevista da empresa Zalando

Determine whether a circular array with magic indexes contains a full circle. The array is circular in the sense that, the entry A[i] points to entry A[A[i]]. Full circle means it covers all the elements of the array. As a follow-up, I was asked to solve the problem in O(1) space. Example: Input: [2,3,1,4,0], Output: true Input: [2,3,2,4,9], Output: false

Respostas da entrevista

Sigiloso

20 de jun. de 2020

``` list_ = [1,0,2,3] length = len(list_) summation_required = length * (length-1) / 2 iter_count = 0 next_item = list_[0] actual_summation = 0 while True: actual_summation += next_item next_item = list_[next_item] iter_count += 1 if iter_count == length: break if summation_required == actual_summation: print("Yess") else: print("Nooo") ```

Sigiloso

8 de nov. de 2020

Why does this code return false for array [1,0,2,3]?