Mar 24, 2021
Q1. Given an array nums containing n+1 integers where each integer is between 1 and n (inclusive), prove that at least duplicate number must exist.Assume that there is only one duplicate number, find the duplicate one.

  1. Input: [1,2,3,2]

  2. output: 2

  1. Input: [2,5,6,7,5]

  2. output: 5

  1. Input: [2,4,7,3,7]

  2. output: 7


Mar 24, 2021
Q2. Given an array of ints length 3, return the sum of all the elements.

  1. Input: sum3([1,2,3])

  2. output: 6

  1. Input: sum3([3,4,6])

  2. output: 13

  1. Input: sum3([3,0,0])

  2. output: 3


Mar 24, 2021
Q3. Given an array of ints length 3, return an array with the elements "rotated left" so {1,2,3} yields {2,3,1}.

  1. Input: rotate_left[4,2,7]

  2. output: [7,3,4]

  1. Input: rotate_left([5,7,3])

  2. output: [7,3,5]

  1. Input: rotate_left([3,0,0])

  2. output: [0,0,3]