Pergunta de entrevista da empresa CA Technologies

How do you find the maximum element in an array without using any loops?

Respostas da entrevista

Sigiloso

29 de ago. de 2018

public class Main { static int max=0; public static void main(String[] args) { int[] arr= new int[]{3,1,4,6,5}; System.out.println(findMax(arr,arr.length-1)); } private static int findMax(int[] arr,int i) { if(i==0) { return max; } if(arr[i]>max){ max=arr[i]; return findMax(arr,i-1); } return max; } }

Sigiloso

6 de fev. de 2018

I gave the solution based on RECURSION.