Comments

Forges3 months ago

const solve = intArray => {
  const result = [];

  intArray.forEach((item, index) => {
    if (index === 0) {
      result.push(item);
    }
    result.push(intArray[result[result.length - 1]]);
  });

  return !!result[result.length - 1];
};

Abdelhamid Ismaila year ago

const solve = (intArray) => {
  const seenIndexes = {}
  let stop = intArray.length
  let next = 0
  while (stop >= 0) {
    if(seenIndexes[next] && seenIndexes[next] === 'seen') {
      return true
    }
    seenIndexes[next] = 'seen'
    next = intArray[next]
    stop--
  }
  return false
};