Any twins
Inputs
values is a list of 0 to 12 whole numbers, each from 0 to 30.
Your tasks
- Use an outer loop over each position
i, and an inner loop over each later positionj. - If
values[i]equalsvalues[j], return true straight away. - If both loops finish, return false.
- Complete
hasTwinsso it returns true or false. Return it, do not print it.
Example
With values = [4, 9, 2, 9], hasTwins returns true.
Rules
- Do not turn the list into a set.
Test data
TEST DATA 1: values is [4, 9, 2, 9]
TEST DATA 2: values is [1, 2, 3]
Practice focus
Nested loops compare every pair and build rows. The slow, simple answer to most problems is two loops. Knowing it is what lets you see how to beat it.