TechantCode
Home
(current)
Programing question
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.
Input: [1,2,3,2]
output: 2
Input: [2,5,6,7,5]
output: 5
Input: [2,4,7,3,7]
output: 7
Mar 24, 2021
Q2. Given an array of ints length 3, return the sum of all the elements.
Input: sum3([1,2,3])
output: 6
Input: sum3([3,4,6])
output: 13
Input: sum3([3,0,0])
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}.
Input: rotate_left[4,2,7]
output: [7,3,4]
Input: rotate_left([5,7,3])
output: [7,3,5]
Input: rotate_left([3,0,0])
output: [0,0,3]