DEV Community

Discussion on: Cake and Duplicates

Collapse
 
nethanjan profile image
nethanjan

Nice, creative solution. But since we know that range is 1..n what about

array_sum = [1, 2, 3, 4, 1].sum
consecutive_sum = n∗(n+1)/2

duplicate = array_sum - consecutive_sum

Collapse
 
rpalo profile image
Ryan Palo

Oh shoot! I can’t believe I didn’t think of that. You’re totally right. Nice one! 👍🏻