THINK FIRST·CODE LATER

← All labs

leastFrequent: the rarest element of an unsorted array

Problem

Write public static int leastFrequent(int[] arr) returning the element that occurs the fewest times; if several tie, return the one appearing earliest in the array. For {1,3,2,1,2,2,3,1} the answer is 3, and for {10,20,30} it is 10.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.