Java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public class Array2ndSmallest{ public static void main (String []args){ int [] arr = { 6 , 2 , 3 , 4 , 5 , 1 }; int first = Integer. MAX_VALUE ; int second = Integer. MIN_VALUE ; for ( int i= 0 ; i<arr. length ; i++){ if (arr[i]<first){ second = first; first = arr[i]; } else if (arr[i]<second && arr[i]!=first) second = arr[i]; } System. out . println ( "second smallest:" +second); } } Python import sys arr = [ 6 , 2 , 3 , 4 , 5 , 1 ]; first = sys . maxsize second = sys . maxsize for i in range ( 0 , len (arr)): if arr[i] < first: second = first first = arr[i] elif arr[i] < second and arr[i] != first: second = arr[i] print ( "second smal...
This blog contains coding/programming and interview questions of MNCs like TCS, Wipro, Infosys, Capgemini, Mindtree, Amazon, Google, Facebook, Flipkart, Cisco, HP, Dell, etc. with placement preparation guides.