Sort by

recency

|

2415 Discussions

|

  • + 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;
    
  • + 0 comments

    Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-electronics-shop-problem-solution.html

  • + 0 comments

    static int getMoneySpent(int[] keyboards, int[] drives, int b) { /* * Write your code here. */ int ans=-1; Arrays.sort(keyboards); Arrays.sort(drives); int i=keyboards.length-1,j=0; int curr=-1; System.out.println(keyboards); System.out.println(drives); while(i>-1 && jb){ i--; }

            else{
                curr=keyboards[i]+drives[j];
                 j++;
            }
    
            if(curr>ans)
            ans=curr;
         }
    
    
         return ans;
    
    }