27 April 2017

Phone Call

My solution:
int phoneCall(int min1, int min2_10, int min11, int s) 
{
    var min = 0;
    while (s > 0)
    {
        if (min == 0)
        {
            if (s >= min1)
            {
                s -= min1;
                min = 1;
            }
            else
                s = 0;
        }
        else if (min == 1)
        {
            if (s >= min2_10 * 9)
            {
                min = 10;
                s -= min2_10 * 9;
            }
            else if (s < min2_10)
            {
                min = 2;
                s = 0;
            }
            else
            {
                min += s / min2_10;
                s = 0;
            }
            
        }
        else if (min == 10)
        {
            if (s < min11)
                min++;
            else
                min += s / min11;
            
            s = 0;
            
        }
    }
    
    return min;
}

Previous Next