Sort by

recency

|

936 Discussions

|

  • + 0 comments
    def taumBday(b, w, bc, wc, z):
        if(bc>wc+z):
            w=b+w
            return (w*wc)+(b*z)
        elif(wc>bc+z):
            wc=bc+z
            return (w*wc)+(b*bc)
        else:
            return (b*bc)+(w*wc)
    
  • + 0 comments

    For typescript this exercise as it is designed will not have a correct answer as the type of the function for this exercise would be BigInt and not number

  • + 0 comments

    Here is my simple c++ solution, you can watch the explanation here : https://youtu.be/T9sxEzAbp-M

    long taumBday(int b, int w, int bc, int wc, int z) {
        long bp = min(bc, wc + z);
        long wp = min(wc, bc + z);
        return bp * b + wp * w;
    }
    
  • + 0 comments
    `
    cost=0 
        flag=0 
        if bc+z<wc:
            flag=1
            cost=cost+(bc+z)*w
        if wc+z<bc:
            flag=2
            cost=cost+(wc+z)*b
        if flag==0:
            cost=(bc*b)+(wc*w)
        if flag==1:
            cost=cost+(b*bc)
        if flag==2:
            cost=cost+(w*wc)
        return cost
        
    

    `

  • + 0 comments

    Here is my one line Python solution! There are three candidates for the lowest cost, buying all of them at the normal price, buying all black presents and converting to white presents, or buying all white presents and converting to black presents. Then, we return the smallest of these prices.

    def taumBday(b, w, bc, wc, z):
        return min([(b + w) * bc + z * w, (b + w) * wc + z * b, b * bc + w * wc])