27 April 2017

Metro Card

My solution:
int[] metroCard(int lastNumberOfDays) 
{
    return lastNumberOfDays == 28 || lastNumberOfDays == 30 ? new [] { 31 } : new [] { 28, 30, 31 };
}

Previous Next

Will You?

My solution:
bool willYou(bool young, bool beautiful, bool loved) 
{
    return (young && beautiful && !loved) || ((!young || !beautiful) && loved);
}

Previous Next

Tennis Set

My solution:
bool tennisSet(int score1, int score2) 
{
    return (Math.Min(score1, score2) < 5 && Math.Max(score1, score2) == 6) || ((Math.Min(score1, score2) == 5 || Math.Min(score1, score2) == 6) && Math.Max(score1, score2) == 7);
}

Previous Next

Arithmetic Expression

My solution:
bool arithmeticExpression(int A, int B, int C) 
{
    return A + B == C || A - B == C || A * B == C || A / B == C && A % B == 0;
}

Previous Next

Is Infinite Process?

My solution:
bool isInfiniteProcess(int a, int b) 
{
    return a > b || Math.Abs(a - b) % 2 == 1;
}

Previous Next

Extra Number

My solution:
int extraNumber(int a, int b, int c) 
{
    return (a == b) ? c : (a == c) ? b : a;
}

Previous Next

Knapsack Light

My solution:
int knapsackLight(int value1, int weight1, int value2, int weight2, int maxW) 
{
    if (weight1 + weight2 <= maxW)
        return value1 + value2;
    else if (weight1 > maxW && weight2 > maxW)
        return 0;
    else if (weight1 > maxW)
        return value2;
    else if (weight2 > maxW)
        return value1;
    else
        return value1 > value2 ? value1 : value2;
}

Previous Next

Reach Next Level

My solution:
bool reachNextLevel(int experience, int threshold, int reward) 
{
    return experience + reward >= threshold;
}

Previous Next

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