Sort by

recency

|

2417 Discussions

|

  • + 0 comments

    C# static int getMoneySpent(int[] keyboards, int[] drives, int b) { int max = -1; Array.Sort(keyboards); Array.Sort(drives);

     int i = 0;
     int j = drives.Length - 1;
    
     while (i <= keyboards.Length - 1 && j >= 0)
     {
         int sum = keyboards[i] + drives[j];
    
         if (sum > b)
         {
             j--;
         }
         else
         {
             i++;
    
             if (sum > max)
             {
                 max = sum;
             }
         }
     }
    
     return max;
    

    }

  • + 0 comments
    costs = []
    
    for i in keyboards:
        for j in drives:
            costs.append (i+j) if (i+j <= b) else costs.append (0)
    return max(costs) if (max(costs) > 0) else -1
    
  • + 0 comments

    This doesn't have a typescript option?

  • + 0 comments

    here is python3 solution to the problem sol1: by taking an empty list def getMoneySpent(keyboards, drives, b): l=[] for i in keyboards: for j in drives: if i+j<=b: l.append(i+j) if not l: return -1 else:
    return max(l) ` sol2: since list might end up taking too much storage def getMoneySpent(keyboards, drives, b): spent=-1 for i in keyboards: for j in drives: total=i+j if total<=b: spent= max(spent,total) return spent

  • + 0 comments
        int maxPrice = -1;
        for(int i=keyboards.length-1; i>=0; i--) {
            int keyboardprice = keyboards[i];
            for(int j=drives.length-1; j>=0; j--) {
                int driveprice = drives[j];
                if(keyboardprice + driveprice <= b) {
                    if(keyboardprice + driveprice > maxPrice) {
                        maxPrice = keyboardprice + driveprice;
                    }
                }
            }
        }
        return maxPrice;