You dont have to sort the entire list. Use bubble sort and run the inner loop just 2 times with if condition as below
for (int i = 0; i a[j]) swap(a[j-1], a[j]);
return a[1];
One needs to think about those scenarios where there are duplicates like 5,3,2,3,1,2,1. The above function will return 1. So better to ask interviewer before implementing.