Your browser (Unknown 0) is no longer supported. Some parts of the website may not work correctly. Please update your browser.

AVAILABLE EXERCISES:

Exercise 9

Bitwise operations (bit-ops)

Exercise 8

Frontend

Exercise 7

Data Structures

Exercise 6

SQL

Exercise 5

Coding skills

Exercise 4

Algorithmic skills

Exercise 3

2017 Contest

Exercise 2

2016 Contest

Exercise 1

2015 Contest

Given two strings representing times of entry and exit from a car parking lot, find the cost of the ticket according to the given billing rules.

Spoken language:

You parked your car in a parking lot and want to compute the total cost of the ticket. The billing rules are as follows:

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

You entered the car parking lot at time E and left at time L. In this task, times are represented as strings in the format `"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

int solution(char *E, char *L);

that, given strings E and L specifying points in time in the format `"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

For example, given `"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

In your solution, focus on ** correctness**. The performance of your solution will not be the focus of the assessment.

Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.

You parked your car in a parking lot and want to compute the total cost of the ticket. The billing rules are as follows:

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

You entered the car parking lot at time E and left at time L. In this task, times are represented as strings in the format `"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

int solution(string &E, string &L);

that, given strings E and L specifying points in time in the format `"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

For example, given `"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

In your solution, focus on ** correctness**. The performance of your solution will not be the focus of the assessment.

Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.

You parked your car in a parking lot and want to compute the total cost of the ticket. The billing rules are as follows:

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

You entered the car parking lot at time E and left at time L. In this task, times are represented as strings in the format `"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

int solution(string &E, string &L);

that, given strings E and L specifying points in time in the format `"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

For example, given `"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

In your solution, focus on ** correctness**. The performance of your solution will not be the focus of the assessment.

Copyright 2009–2024 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

class Solution { public int solution(string E, string L); }

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

int solution(String E, String L);

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

func Solution(E string, L string) int

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

class Solution { public int solution(String E, String L); }

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

class Solution { public int solution(String E, String L); }

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

function solution(E, L);

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

fun solution(E: String, L: String): Int

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

function solution(E, L)

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

int solution(NSString *E, NSString *L);

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

function solution(E: PChar; L: PChar): longint;

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

function solution($E, $L);

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

sub solution { my ($E, $L) = @_; ... }

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

def solution(E, L)

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

def solution(e, l)

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

object Solution { def solution(e: String, l: String): Int }

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

public func solution(_ E : inout String, _ L : inout String) -> Int

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

function solution(E: string, L: string): number;

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.

- The entrance fee of the car parking lot is 2;
- The first full or partial hour costs 3;
- Each successive full or partial hour (after the first) costs 4.

`"HH:MM"` (where `"HH"` is a two-digit number between 0 and 23, which stands for hours, and `"MM"` is a two-digit number between 0 and 59, which stands for minutes).

Write a function:

Private Function solution(E As String, L As String) As Integer

`"HH:MM"`, returns the total cost of the parking bill from your entry at time E to your exit at time L. You can assume that E describes a time before L on the same day.

`"10:00"` and `"13:21"` your function should return 17, because the entrance fee equals 2, the first hour costs 3 and there are two more full hours and part of a further hour, so the total cost is 2 + 3 + (3 * 4) = 17. Given `"09:42"` and `"11:42"` your function should return 9, because the entrance fee equals 2, the first hour costs 3 and the second hour costs 4, so the total cost is 2 + 3 + 4 = 9.

Assume that:

- strings E and L follow the format "
HH:MM" strictly;- string E describes a time before L on the same day.

** correctness**. The performance of your solution will not be the focus of the assessment.