Uber phone Interview - Random odd number from the given array

1779
Nov 16, 2018
May 24, 2019
  1. Get a random element from the given array -- > was easy
  2. Get the Random Odd number from the given array --> was easy too
    public static int getRandomOdd(int [] arr) {
    	while(true) {
    		int ran = new Random().nextInt(arr.length);
        	if(arr[ran]%2 !=0) { 
        		 return arr[ran];
        	}
    	}
    }
    
Comments (7)