Goldman Coderpad
Anonymous User
4826

Today I had my coderpad round. I was asked two questions:

  1. Median of two sorted arrays
  2. Find a cycle in an array: You are given an integer array of size N.
    Every element of the array is greater than or equal to 0.
    Starting from arr[startIndex], follow each element to the index it points to. Continue to do this until you find a cycle.
    Return the length of the cycle. If no cycle is found return -1

Examples:
countLengthOfCycle([1, 0], 1) == 2 ,
countLengthOfCycle([1, 2, 0], 0) == 3

Comments (5)