I would request you guys to suggest an efficient way to check if every odd element is greater than every even element in array in java, using just arrays
Thanks
I would request you guys to suggest an efficient way to check if every odd element is greater than every even element in array in java, using just arrays
Thanks
Iterate over the array once, and keep track of the smallest odd element and the highest even element. Then check that the first is higher than the second (i.e. check that the minimum odd element is higher than the maximum even element).
You can even improve the algorithm to fail fast. At any point while iterating over the array, if the current smallest odd element becomes smaller than the current highest even element, you can quit the loop and return false.