HackerRank 'Taum and B'day' Solution

Martin Kysel · March 15, 2015

Short Problem Definition:

Taum is planning to celebrate the birthday of his friend Diksha. There are two types of gifts that Diksha wants from Taum: one is black and the other is white. To make her happy, Taum has to buy B number of black gifts and W number of white gifts.

Taum and B’day

Complexity:

time complexity is O(1)

space complexity is O(1)

Execution:

The cost for each present is either the cost of its category, or the cost of the other category + the conversion cost. Just select the minimum.

Solution:

#!/usr/bin/py
if __name__ == '__main__':
    t = input()
    for _ in xrange(t):
        b, w = map(int, raw_input().split())
        x, y, z = map(int, raw_input().split())
        
        print min(b*x, b*(y+z)) + min(w*(x+z), w*y)

Twitter, Facebook

To learn more about solving Coding Challenges in Python, I recommend these courses: Educative.io Python Algorithms, Educative.io Python Coding Interview.