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.
staticMap<String,Boolean>memo=newHashMap<>();publicstaticStringpermutationGame(List<Integer>arr){// Write your code herememo.clear();returnfindWinner(arr)?"Bob":"Alice";}staticbooleanisIncreasing(List<Integer>arr){for(inti=0;i<arr.size()-1;i++){if(arr.get(i)>arr.get(i+1)){returnfalse;}}returntrue;}staticbooleanfindWinner(List<Integer>arr){Stringkey=arr.toString();if(memo.containsKey(key)){returnmemo.get(key);}if(isIncreasing(arr)){memo.put(key,true);returntrue;}for(inti=0;i<arr.size();i++){if(findWinner(Stream.concat(arr.subList(0,i).stream(),arr.subList(i+1,arr.size()).stream()).collect(Collectors.toList()))){memo.put(key,false);returnfalse;}}memo.put(key,true);returntrue;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Permutation game
You are viewing a single comment's thread. Return to all comments →
@judge_angry solution: