Sort by

recency

|

133 Discussions

|

  • + 0 comments

    Python3

    def gamingArray(arr):
        # Write your code here
        helper = sorted(arr, reverse=True)
        d = dict()
        for i in range(len(arr)):
            d[arr[i]] = i
        count = 0
        n = len(arr) - 1
        for maxVal in helper:
            if d[maxVal] <= n:
                n = d[maxVal] - 1
                count += 1
            if n < 0:
                break
        return 'BOB' if count % 2 == 1 else 'ANDY'
    
  • + 0 comments
    public static String gamingArray(List<Integer> arr) {
    // Write your code here
    
        int count = 0, end = -1;
    
        for(int i = 0; i< arr.size(); i++){
    
                count++;
                end = arr.indexOf(Collections.max(arr));
                //System.out.println("MAX: "+ Collections.max(arr) +" Ind: "+end);
    
                for(int j = end; j< arr.size(); j++){
                    //System.out.println("J: "+j+" Remove: "+ arr.get(j));
                    arr.remove(j);
                    j--;
            }
    
            // for(Integer k:arr){
            //     System.out.println("Arr: "+k);
            // }
        }
    
    
                I dont know why all my test cases were not getting successful. Could any one help me with my solution and clearly explain how to work with constrains 
    
        if(count%2==0)    return "ANDY";
        else    return "BOB";
    
    }
    
  • + 0 comments

    python3 def gamingArray(arr): curr_max = 0 bob_turn = True for n in arr: if n > curr_max: curr_max = n bob_turn = not bob_turn return ['ANDY', 'BOB'][not bob_turn] `

  • + 1 comment

    what is the issue in my code I am getting time limit exceed.

    def gamingArray(arr): count =0 arrlen = len(arr) for i in range(arrlen): if len(arr)>0: idx=arr.index(max(arr)) arr=arr[:idx] count+=1 winner = "ANDY" if count % 2 == 0 else "BOB" return winner

  • + 0 comments

    Thanks