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

UPCOMING CHALLENGES:

Future Mobility

CURRENT CHALLENGES:

Grand Challenge

PAST CHALLENGES

Decoding Master

Digital Gold

Selenium 2018

Germanium 2018

Gallium 2018

Zinc 2018

Cuprum 2018

Cutting Complexity

Nickel 2018

Cobaltum 2018

Ferrum 2018

Manganum 2017

Chromium 2017

Vanadium 2016

Titanium 2016

Scandium 2016

Calcium 2015

Kalium 2015

Argon 2015

Chlorum 2014

Sulphur 2014

Phosphorus 2014

Silicium 2014

Aluminium 2014

Magnesium 2014

Natrium 2014

Neon 2014

Fluorum 2014

Oxygenium 2014

Nitrogenium 2013

Carbo 2013

Boron 2013

Beryllium 2013

Lithium 2013

Helium 2013

Hydrogenium 2013

Omega 2013

Psi 2012

Chi 2012

Phi 2012

Upsilon 2012

Tau 2012

Sigma 2012

Rho 2012

Pi 2012

Omicron 2012

Xi 2012

Nu 2011

Mu 2011

Lambda 2011

Kappa 2011

Iota 2011

Theta 2011

Eta 2011

Zeta 2011

Epsilon 2011

Delta 2011

Gamma 2011

Beta 2010

Alpha 2010

ambitious

Programming language:
Spoken language:

Chin is fighting with his mortal enemy, Cho. Chin and Cho are pacifists, so their fight is actually a game of checkers on an infinite board. There are two types of pieces in checkers: pawns and queens. Chin is left with his last piece: a queen. Now it is Chin's turn − the last turn in the game.

Pieces can move only diagonally and forward. A pawn always moves one step in the up-right or up-left direction. A queen can move any number of steps in one of these two directions.

If there is a piece belonging to Cho on the line of Chin's queen's movement, Chin can beat it by leaping over it and optionally passing some more empty fields. Chin can beat only one of Cho's pieces in one move. After beating one of Cho's pieces in this way, Chin can continue his turn and make another move, but only if he can beat another piece.

Chin gains 1 point for beating a pawn and 10 points for beating a queen. Now Chin wants to know the maximum number of points he can score in a single turn. Can you help?

Write a function:

int solution(int X[], int Y[], int N, char *T);

that, given the positions of all the pieces on the board, counts the maximum number of points Chin can score in one turn. X and Y are arrays of N coordinates of pieces: an `K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

T is a string of N characters in which the `K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

the function should return 10. This situation is depicted in the following illustration. Chin's queen is green, Cho's pawns are checked red and her queens are plain red. The optimal turn (sequence of moves) is marked by a green path.

Given:

the function should return 2. Note that Chin's queen cannot jump over Cho's queen as her pawn is right behind it.

Finally, given:

the function should return 12. Remember that the board is infinite and the queen can jump onto cells with negative coordinates.

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

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

Chin is fighting with his mortal enemy, Cho. Chin and Cho are pacifists, so their fight is actually a game of checkers on an infinite board. There are two types of pieces in checkers: pawns and queens. Chin is left with his last piece: a queen. Now it is Chin's turn − the last turn in the game.

Pieces can move only diagonally and forward. A pawn always moves one step in the up-right or up-left direction. A queen can move any number of steps in one of these two directions.

If there is a piece belonging to Cho on the line of Chin's queen's movement, Chin can beat it by leaping over it and optionally passing some more empty fields. Chin can beat only one of Cho's pieces in one move. After beating one of Cho's pieces in this way, Chin can continue his turn and make another move, but only if he can beat another piece.

Chin gains 1 point for beating a pawn and 10 points for beating a queen. Now Chin wants to know the maximum number of points he can score in a single turn. Can you help?

Write a function:

int solution(vector<int> &X, vector<int> &Y, string &T);

that, given the positions of all the pieces on the board, counts the maximum number of points Chin can score in one turn. X and Y are arrays of N coordinates of pieces: an `K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

T is a string of N characters in which the `K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

the function should return 10. This situation is depicted in the following illustration. Chin's queen is green, Cho's pawns are checked red and her queens are plain red. The optimal turn (sequence of moves) is marked by a green path.

Given:

the function should return 2. Note that Chin's queen cannot jump over Cho's queen as her pawn is right behind it.

Finally, given:

the function should return 12. Remember that the board is infinite and the queen can jump onto cells with negative coordinates.

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

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

Chin is fighting with his mortal enemy, Cho. Chin and Cho are pacifists, so their fight is actually a game of checkers on an infinite board. There are two types of pieces in checkers: pawns and queens. Chin is left with his last piece: a queen. Now it is Chin's turn − the last turn in the game.

Pieces can move only diagonally and forward. A pawn always moves one step in the up-right or up-left direction. A queen can move any number of steps in one of these two directions.

If there is a piece belonging to Cho on the line of Chin's queen's movement, Chin can beat it by leaping over it and optionally passing some more empty fields. Chin can beat only one of Cho's pieces in one move. After beating one of Cho's pieces in this way, Chin can continue his turn and make another move, but only if he can beat another piece.

Chin gains 1 point for beating a pawn and 10 points for beating a queen. Now Chin wants to know the maximum number of points he can score in a single turn. Can you help?

Write a function:

class Solution { public int solution(int[] X, int[] Y, string T); }

that, given the positions of all the pieces on the board, counts the maximum number of points Chin can score in one turn. X and Y are arrays of N coordinates of pieces: an `K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

T is a string of N characters in which the `K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

the function should return 10. This situation is depicted in the following illustration. Chin's queen is green, Cho's pawns are checked red and her queens are plain red. The optimal turn (sequence of moves) is marked by a green path.

Given:

the function should return 2. Note that Chin's queen cannot jump over Cho's queen as her pawn is right behind it.

Finally, given:

the function should return 12. Remember that the board is infinite and the queen can jump onto cells with negative coordinates.

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

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

Write a function:

func Solution(X []int, Y []int, T string) int

`K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

`K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

Given:

Finally, given:

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

Write a function:

class Solution { public int solution(int[] X, int[] Y, String T); }

`K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

`K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

Given:

Finally, given:

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

Write a function:

function solution(X, Y, T);

`K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

`K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

Given:

Finally, given:

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

Write a function:

function solution(X, Y, T)

`K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

`K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

Given:

Finally, given:

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

Write a function:

int solution(NSMutableArray *X, NSMutableArray *Y, NSString *T);

`K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

`K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

Given:

Finally, given:

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

Write a function:

function solution(X: array of longint; Y: array of longint; N: longint; T: PChar): longint;

`K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

`K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

Given:

Finally, given:

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

Write a function:

function solution($X, $Y, $T);

`K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

`K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

Given:

Finally, given:

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

Write a function:

sub solution { my ($X, $Y, $T)=@_; my @X=@$X; my @Y=@$Y; ... }

`K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

`K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

Given:

Finally, given:

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

Write a function:

def solution(X, Y, T)

`K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

`K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

Given:

Finally, given:

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

Write a function:

def solution(x, y, t)

`K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

`K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

Given:

Finally, given:

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

Write a function:

object Solution { def solution(x: Array[Int], y: Array[Int], t: String): Int }

`K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

`K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

Given:

Finally, given:

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

Write a function:

public func solution(inout X : [Int], inout _ Y : [Int], inout _ T : String) -> Int

`K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

`K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

Given:

Finally, given:

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

Write a function:

public func solution(_ X : inout [Int], _ Y : inout [Int], _ T : inout String) -> Int

`K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

`K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

Given:

Finally, given:

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

Write a function:

Private Function solution(X As Integer(), Y As Integer(), T As String) As Integer

`K`-th piece (0 ≤ K < N) occupies board position (`X[K]`, `Y[K]`); i.e. it appears in the `X[K]`-th column and `Y[K]`-th row. Each piece occupies a black field.

`K`-th character represents the type of the `K`-th piece: `'p'` represents one of Cho's pawns and `'q'` one of Cho's queens, whilst `'X'` represents Chin's queen.

For example, given:

Given:

Finally, given:

Write an ** efficient** algorithm for the following assumptions:

- arrays X, Y and string T have the same length N;
- N is an integer within the range [1..100,000];
- each element of arrays X, Y is an integer within the range [0..100,000,000];
- no two pieces have the same coordinates;
- each piece is located on a black field (field (0, 0) is black);
- string T consists only of the following characters: "
p", "q" and/or "X";- string T contains exactly one character "
X".

Information about upcoming challenges, solutions and lessons directly in your inbox.

© 2009–2018 Codility Ltd., registered in England and Wales (No. 7048726). VAT ID GB981191408. Registered office: 107 Cheapside, London EC2V 6DN