Loading...
Is this your company?
How do you find the maximum element in an array without using any loops?
Anonymous
I gave the solution based on RECURSION.
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; } }
Check out your Company Bowl for anonymous work chats.
Get actionable career advice tailored to you by joining more bowls.
Stay ahead in opportunities and insider tips by following your dream companies.
Get personalised job recommendations and updates by starting your searches.