We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Here is my solution to handle large inputs in Java;
privatestaticTreeMap<Integer,Integer>indexMaxMap=newTreeMap<>();privatestaticvoidcreateIndexMaxMap(List<Integer>arr){indexMaxMap.clear();for(inti=0;i<arr.size();i++){indexMaxMap.put(arr.get(i),i);}}privatestaticList<Integer>getNewList(List<Integer>arr){intlastIndex=arr.size()-1;while(indexMaxMap.lastEntry().getValue()>lastIndex){indexMaxMap.remove(indexMaxMap.lastKey());}intindex=indexMaxMap.remove(indexMaxMap.lastKey());System.out.println("Last index: "+index);returnarr.subList(0,index);}/* * Complete the 'gamingArray' function below. * * The function is expected to return a STRING. * The function accepts INTEGER_ARRAY arr as parameter. */publicstaticStringgamingArray(List<Integer>arr){createIndexMaxMap(arr);intmoveCount=0;while(arr.size()>0){arr=getNewList(arr);moveCount++;}if(moveCount%2==1){return"BOB";}return"ANDY";}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Gaming Array 1
You are viewing a single comment's thread. Return to all comments →
Here is my solution to handle large inputs in Java;