You could initialize lowest and secondLowest each to Int.max and avoid the need to check whether they're 0 every time through your loop.
This potentially sorts the array twice. Even if the compiler magically optimizes the second sort away, you're still sorting the whole array, which is much more work than you need to do.
Loading collection data...
You could initialize lowest and secondLowest each to Int.max and avoid the need to check whether they're 0 every time through your loop.
This potentially sorts the array twice. Even if the compiler magically optimizes the second sort away, you're still sorting the whole array, which is much more work than you need to do.