Sort by

recency

|

134 Discussions

|

  • + 0 comments
    func findMax(arr *[]int32) int {
        max := (*arr)[0]
        index := 0
        
        for i:=1; i< len(*arr); i++ {
            if max < (*arr)[i]{
                max = (*arr)[i]
                index = i
            }   
        }
        return index
    }
    
    
    func gamingArray(arr []int32) string {
    	i := 0
    
    	for 0 < len(arr) {
    		index := findMax(&arr)
    		arr = arr[:index]
    		i++
    	}
    
    	if i%2 == 0 {
    		return "ANDY"
    	}
    	return "BOB"
    }
    
  • + 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

      The issue is that in every iteration you are finding the max value in array and then slicing, this is a n^2 solution thats why