improved the solutions for 'smallest' and 'largest' to eliminate nested loops.