3
1
4
1
5
[0][1][2][3][4]
Brute force
▸1for i ← 0 to n − 2:2 for j ← i + 1 to n − 1:3 if arr[i] == arr[j]:4 return true5return false
state
—
Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.
Try one problemGiven an integer array, return true if any value appears at least twice, and false if every element is distinct.
▸1for i ← 0 to n − 2:2 for j ← i + 1 to n − 1:3 if arr[i] == arr[j]:4 return true5return false
line 1Return true if any value appears at least twice.