Easy

You are playing an RPG game. Currently your experience points (XP) total is equal to experience. To reach the next level your XP should be at least at threshold. If you kill the monster in front of you, you will gain more experience points in the amount of the reward.

Given values experience, threshold and reward, check if you reach the next level after killing the monster.

Example

  • For experience = 10, threshold = 15, and reward = 5, the output should be
    reachNextLevel(experience, threshold, reward) = true;
  • For experience = 10, threshold = 15, and reward = 4, the output should be
    reachNextLevel(experience, threshold, reward) = false.

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] integer experience

    Guaranteed constraints:
    3 ≤ experience ≤ 250.

  • [input] integer threshold

    Guaranteed constraints:
    5 ≤ threshold ≤ 300.

  • [input] integer reward

    Guaranteed constraints:
    2 ≤ reward ≤ 65.

  • [output] boolean

    • true if you reach the next level, false otherwise.

[C] Syntax Tips

// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
    char * answer = malloc(strlen(name) + 8);
    printf("This prints to the console when you Run Tests");
    strcpy(answer, "Hello, ");
    strcat(answer, name);
    return answer;
}

더보기

Solution

bool reachNextLevel(int experience,int threshold,int reward)
{
	return experience+reward>=threshold;
}
728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> Is Infinite Process?  (0) 2020.04.07
<Codesignal> Extra Number  (0) 2020.04.07
<Codesignal> Phone Call  (0) 2020.04.07
<Codesignal> Late Ride  (0) 2020.04.07
<Codesignal> Max Multiple  (0) 2020.04.07

Easy

Some phone usage rate may be described as follows:

  • first minute of a call costs min1 cents,
  • each minute from the 2nd up to 10th (inclusive) costs min2_10 cents
  • each minute after 10th costs min11 cents.

You have s cents on your account before the call. What is the duration of the longest call (in minutes rounded down to the nearest integer) you can have?

Example

For min1 = 3, min2_10 = 1, min11 = 2, and s = 20, the output should be
phoneCall(min1, min2_10, min11, s) = 14.

Here's why:

  • the first minute costs 3 cents, which leaves you with 20 - 3 = 17 cents;
  • the total cost of minutes 2 through 10 is 1 * 9 = 9, so you can talk 9 more minutes and still have 17 - 9 = 8 cents;
  • each next minute costs 2 cents, which means that you can talk 8 / 2 = 4 more minutes.

Thus, the longest call you can make is 1 + 9 + 4 = 14 minutes long.

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] integer min1

    Guaranteed constraints:
    1 ≤ min1 ≤ 10.

  • [input] integer min2_10

    Guaranteed constraints:
    1 ≤ min2_10 ≤ 10.

  • [input] integer min11

    Guaranteed constraints:
    1 ≤ min11 ≤ 10.

  • [input] integer s

    Guaranteed constraints:
    2 ≤ s ≤ 500.

  • [output] integer

[C] Syntax Tips

// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
    char * answer = malloc(strlen(name) + 8);
    printf("This prints to the console when you Run Tests");
    strcpy(answer, "Hello, ");
    strcat(answer, name);
    return answer;
}

더보기

Solution

int phoneCall(int min1,int min2_10,int min11,int s)
{
	return s<min1?0:s<min1+9*min2_10?(s-min1)/min2_10+1:(s-min1-9*min2_10)/min11+10;
}
728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> Extra Number  (0) 2020.04.07
<Codesignal> Reach Next Level  (0) 2020.04.07
<Codesignal> Late Ride  (0) 2020.04.07
<Codesignal> Max Multiple  (0) 2020.04.07
<Codesignal> Seats in Theater  (0) 2020.04.07

Easy

One night you go for a ride on your motorcycle. At 00:00 you start your engine, and the built-in timer automatically begins counting the length of your ride, in minutes. Off you go to explore the neighborhood.

When you finally decide to head back, you realize there's a chance the bridges on your route home are up, leaving you stranded! Unfortunately, you don't have your watch on you and don't know what time it is. All you know thanks to the bike's timer is that n minutes have passed since 00:00.

Using the bike's timer, calculate the current time. Return an answer as the sum of digits that the digital timer in the format hh:mm would show.

Example

  • For n = 240, the output should be
    lateRide(n) = 4.

    Since 240 minutes have passed, the current time is 04:00. The digits sum up to 0 + 4 + 0 + 0 = 4, which is the answer.

  • For n = 808, the output should be
    lateRide(n) = 14.

    808 minutes mean that it's 13:28 now, so the answer should be 1 + 3 + 2 + 8 = 14.

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] integer n

    The duration of your ride, in minutes. It is guaranteed that you've been riding for less than a day (24 hours).

    Guaranteed constraints:
    0 ≤ n < 60 · 24.

  • [output] integer

    • The sum of the digits the digital timer would show.

[C] Syntax Tips

// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
    char * answer = malloc(strlen(name) + 8);
    printf("This prints to the console when you Run Tests");
    strcpy(answer, "Hello, ");
    strcat(answer, name);
    return answer;
}

더보기

Solution

int lateRide(int n)
{
	return n/600+(n/60)%10+(n%60)/10+n%10;
}
728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> Reach Next Level  (0) 2020.04.07
<Codesignal> Phone Call  (0) 2020.04.07
<Codesignal> Max Multiple  (0) 2020.04.07
<Codesignal> Seats in Theater  (0) 2020.04.07
<Codesignal> Candies  (0) 2020.04.07

Easy

Given a divisor and a bound, find the largest integer N such that:

  • N is divisible by divisor.
  • N is less than or equal to bound.
  • N is greater than 0.

It is guaranteed that such a number exists.

Example

For divisor = 3 and bound = 10, the output should be
maxMultiple(divisor, bound) = 9.

The largest integer divisible by 3 and not larger than 10 is 9.

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] integer divisor

    Guaranteed constraints:
    2 ≤ divisor ≤ 10.

  • [input] integer bound

    Guaranteed constraints:
    5 ≤ bound ≤ 100.

  • [output] integer

    • The largest integer not greater than bound that is divisible by divisor.

[C] Syntax Tips

// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
    char * answer = malloc(strlen(name) + 8);
    printf("This prints to the console when you Run Tests");
    strcpy(answer, "Hello, ");
    strcat(answer, name);
    return answer;
}

더보기

Solution

int maxMultiple(int divisor,int bound)
{
	return bound-bound%divisor;
}
728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> Phone Call  (0) 2020.04.07
<Codesignal> Late Ride  (0) 2020.04.07
<Codesignal> Seats in Theater  (0) 2020.04.07
<Codesignal> Candies  (0) 2020.04.07
<Codesignal> Largest Number  (0) 2020.04.07

Easy

Your friend advised you to see a new performance in the most popular theater in the city. He knows a lot about art and his advice is usually good, but not this time: the performance turned out to be awfully dull. It's so bad you want to sneak out, which is quite simple, especially since the exit is located right behind your row to the left. All you need to do is climb over your seat and make your way to the exit.

The main problem is your shyness: you're afraid that you'll end up blocking the view (even if only for a couple of seconds) of all the people who sit behind you and in your column or the columns to your left. To gain some courage, you decide to calculate the number of such people and see if you can possibly make it to the exit without disturbing too many people.

Given the total number of rows and columns in the theater (nRows and nCols, respectively), and the row and column you're sitting in, return the number of people who sit strictly behind you and in your column or to the left, assuming all seats are occupied.

Example

For nCols = 16, nRows = 11, col = 5, and row = 3, the output should be
seatsInTheater(nCols, nRows, col, row) = 96.

Here is what the theater looks like:

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] integer nCols

    An integer, the number of theater's columns.

    Guaranteed constraints:
    1 ≤ nCols ≤ 1000.

  • [input] integer nRows

    An integer, the number of theater's rows.

    Guaranteed constraints:
    1 ≤ nRows ≤ 1000.

  • [input] integer col

    An integer, the column number of your own seat (1-based).

    Guaranteed constraints:
    1 ≤ col ≤ nCols.

  • [input] integer row

    An integer, the row number of your own seat (1-based).

    Guaranteed constraints:
    1 ≤ row ≤ nRows.

  • [output] integer

    • The number of people who sit strictly behind you and in your column or to the left.

[C] Syntax Tips

// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
    char * answer = malloc(strlen(name) + 8);
    printf("This prints to the console when you Run Tests");
    strcpy(answer, "Hello, ");
    strcat(answer, name);
    return answer;
}

더보기

Solution

int seatsInTheater(int nCols,int nRows,int col,int row)
{
	return (nCols-col+1)*(nRows-row);
}
728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> Late Ride  (0) 2020.04.07
<Codesignal> Max Multiple  (0) 2020.04.07
<Codesignal> Candies  (0) 2020.04.07
<Codesignal> Largest Number  (0) 2020.04.07
<Codesignal> Add Two Digits  (0) 2020.04.07

Easy

n children have got m pieces of candy. They want to eat as much candy as they can, but each child must eat exactly the same amount of candy as any other child. Determine how many pieces of candy will be eaten by all the children together. Individual pieces of candy cannot be split.

Example

For n = 3 and m = 10, the output should be
candies(n, m) = 9.

Each child will eat 3 pieces. So the answer is 9.

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] integer n

    The number of children.

    Guaranteed constraints:
    1 ≤ n ≤ 10.

  • [input] integer m

    The number of pieces of candy.

    Guaranteed constraints:
    2 ≤ m ≤ 100.

  • [output] integer

    • The total number of pieces of candy the children will eat provided they eat as much as they can and all children eat the same amount.

[C] Syntax Tips

// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
    char * answer = malloc(strlen(name) + 8);
    printf("This prints to the console when you Run Tests");
    strcpy(answer, "Hello, ");
    strcat(answer, name);
    return answer;
}

더보기

Solution

int candies(int n,int m)
{
	return m-m%n;
}
728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> Max Multiple  (0) 2020.04.07
<Codesignal> Seats in Theater  (0) 2020.04.07
<Codesignal> Largest Number  (0) 2020.04.07
<Codesignal> Add Two Digits  (0) 2020.04.07
<Codesignal> Sudoku  (0) 2020.04.06

Easy

Given an integer n, return the largest number that contains exactly n digits.

Example

For n = 2, the output should be
largestNumber(n) = 99.

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] integer n

    Guaranteed constraints:
    1 ≤ n ≤ 9.

  • [output] integer

    • The largest integer of length n.

[C] Syntax Tips

// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
    char * answer = malloc(strlen(name) + 8);
    printf("This prints to the console when you Run Tests");
    strcpy(answer, "Hello, ");
    strcat(answer, name);
    return answer;
}

더보기

Solution

int largestNumber(int n)
{
	int N=0;

	for(int i=0;i<n;i++)
	{
		N*=10;
		N+=9;
	}

	return N;
}
728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> Seats in Theater  (0) 2020.04.07
<Codesignal> Candies  (0) 2020.04.07
<Codesignal> Add Two Digits  (0) 2020.04.07
<Codesignal> Sudoku  (0) 2020.04.06
<Codesignal> spiralNumbers  (0) 2020.04.06

Easy

You are given a two-digit integer n. Return the sum of its digits.

Example

For n = 29, the output should be
addTwoDigits(n) = 11.

Input/Output

  • [execution time limit] 0.5 seconds (c)

  • [input] integer n

    A positive two-digit integer.

    Guaranteed constraints:
    10 ≤ n ≤ 99.

  • [output] integer

    • The sum of the first and second digits of the input number.

[C] Syntax Tips

// Prints help message to the console
// Returns a string
char * helloWorld(char * name) {
    char * answer = malloc(strlen(name) + 8);
    printf("This prints to the console when you Run Tests");
    strcpy(answer, "Hello, ");
    strcat(answer, name);
    return answer;
}

더보기

Solution

int addTwoDigits(int n)
{
	return n/10+n%10;
}
728x90

'Codesignal' 카테고리의 다른 글

<Codesignal> Candies  (0) 2020.04.07
<Codesignal> Largest Number  (0) 2020.04.07
<Codesignal> Sudoku  (0) 2020.04.06
<Codesignal> spiralNumbers  (0) 2020.04.06
<Codesignal> messageFromBinaryCode  (0) 2020.04.06

+ Recent posts