Showing posts with label Intro Gates. Show all posts
Showing posts with label Intro Gates. Show all posts

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

Late Ride

My solution:
int lateRide(int n) 
{
    return (n / 60) / 10 + (n / 60) % 10 + (n % 60) / 10 + (n % 60) % 10;
}

Previous Next

Circle Of Numbers

My solution:
int circleOfNumbers(int n, int firstNumber) 
{
    return (firstNumber + n / 2) % n;
}

Previous Next

Max Multiple

My solution:
int maxMultiple(int divisor, int bound) 
{
    return (bound / divisor) * divisor;
}

Previous Next

Seats In Theater

My solution:
int seatsInTheater(int nCols, int nRows, int col, int row) 
{
    return (nCols - col + 1) * (nRows - row);
}

Previous Next

Candies

My solution:
int candies(int n, int m) 
{
    return m / n * n;
}

Largest Number

My solution:
int largestNumber(int n) 
{
    return int.Parse(new string('9', n));
}

Previous Next

26 April 2017

Add Two Digits

My solution:
int addTwoDigits(int n) 
{
    return n % 10 + n / 10;
}

Previous Next