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

Given a sequence S of integers, find a number of increasing sequences I such that every two consecutive elements in I appear in S, but on the opposite sides of the first element of I.

Programming language:
Spoken language:

Elliot the Hawk has a very important task − the breeding season has come. He needs to prepare a nest in which his mating partner Eleonora will lay eggs, then look after her until they switch responsibility for taking care of the eggs.

There are N birds' nests standing in a line, one after another. Every two nests are positioned at distinct heights.

Elliot needs to pick a nest in which Eleonora will lay her eggs. Then, each day, Elliot will hunt from one of the other nests. At the end of the day, he will bring the food to Eleonora and move to some other nest on the opposite side of their own nest. He can hunt from each nest at most once. Moreover, on each day he needs to hunt from a nest that is positioned higher than the previous nest, and higher than their own nest.

Elliot can return to their own nest and switch roles with Eleonora at any time. In particular, he may simply prepare their nest, then refrain from hunting at all.

For example, assume the nests are positioned at heights `4 6 2 1 5`. Elliot can, for instance, prepare the nest at height `1`, then hunt from the nest at height `4`, on the next day hunt from the nest at height `5`, and on the last day hunt from the nest at height `6`:

Note that in this situation, Elliot cannot hunt from the nest at height `6` just after hunting from the nest at height `4`, because these two nests are on the same side of his own nest. Also, after hunting from the rightmost nest, he cannot hunt from the leftmost nest, as it is lower than the previous one. If Elliot chooses the nest at height `6` as their own nest, then he cannot hunt at all, because all other nests are placed lower.

Elliot wonders how many possible ways there are for him to choose their nest and then hunt until he changes places with Eleonora. As the result may be very large, count the number of possibilities modulo 10^{9} + 7 (1,000,000,007).

Write a function:

int solution(int H[], int N);

that, given a sequence of heights of nests, returns the remainder from the division by 1,000,000,007 of the number of possible ways for Elliot to choose the nest and hunt.

For example, given:

the function should return 7. All the possible ways for Elliot to choose the nest and hunt are as follows, listed one per line. The first number in each line denotes the height of Elliot's own nest, and each consecutive number describes the height of a nest he will hunt from.

On the other hand, for the following array:

the function should return 23. One of the possible ways Elliot can act is depicted in the figure above.

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

- N is an integer within the range [1..50,000];
- each element of array H is an integer within the range [1..1,000,000,000];
- the elements of H are all distinct.

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

Elliot the Hawk has a very important task − the breeding season has come. He needs to prepare a nest in which his mating partner Eleonora will lay eggs, then look after her until they switch responsibility for taking care of the eggs.

There are N birds' nests standing in a line, one after another. Every two nests are positioned at distinct heights.

Elliot needs to pick a nest in which Eleonora will lay her eggs. Then, each day, Elliot will hunt from one of the other nests. At the end of the day, he will bring the food to Eleonora and move to some other nest on the opposite side of their own nest. He can hunt from each nest at most once. Moreover, on each day he needs to hunt from a nest that is positioned higher than the previous nest, and higher than their own nest.

Elliot can return to their own nest and switch roles with Eleonora at any time. In particular, he may simply prepare their nest, then refrain from hunting at all.

For example, assume the nests are positioned at heights `4 6 2 1 5`. Elliot can, for instance, prepare the nest at height `1`, then hunt from the nest at height `4`, on the next day hunt from the nest at height `5`, and on the last day hunt from the nest at height `6`:

Note that in this situation, Elliot cannot hunt from the nest at height `6` just after hunting from the nest at height `4`, because these two nests are on the same side of his own nest. Also, after hunting from the rightmost nest, he cannot hunt from the leftmost nest, as it is lower than the previous one. If Elliot chooses the nest at height `6` as their own nest, then he cannot hunt at all, because all other nests are placed lower.

Elliot wonders how many possible ways there are for him to choose their nest and then hunt until he changes places with Eleonora. As the result may be very large, count the number of possibilities modulo 10^{9} + 7 (1,000,000,007).

Write a function:

int solution(vector<int> &H);

that, given a sequence of heights of nests, returns the remainder from the division by 1,000,000,007 of the number of possible ways for Elliot to choose the nest and hunt.

For example, given:

the function should return 7. All the possible ways for Elliot to choose the nest and hunt are as follows, listed one per line. The first number in each line denotes the height of Elliot's own nest, and each consecutive number describes the height of a nest he will hunt from.

On the other hand, for the following array:

the function should return 23. One of the possible ways Elliot can act is depicted in the figure above.

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

- N is an integer within the range [1..50,000];
- each element of array H is an integer within the range [1..1,000,000,000];
- the elements of H are all distinct.

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

Elliot the Hawk has a very important task − the breeding season has come. He needs to prepare a nest in which his mating partner Eleonora will lay eggs, then look after her until they switch responsibility for taking care of the eggs.

There are N birds' nests standing in a line, one after another. Every two nests are positioned at distinct heights.

Elliot needs to pick a nest in which Eleonora will lay her eggs. Then, each day, Elliot will hunt from one of the other nests. At the end of the day, he will bring the food to Eleonora and move to some other nest on the opposite side of their own nest. He can hunt from each nest at most once. Moreover, on each day he needs to hunt from a nest that is positioned higher than the previous nest, and higher than their own nest.

Elliot can return to their own nest and switch roles with Eleonora at any time. In particular, he may simply prepare their nest, then refrain from hunting at all.

For example, assume the nests are positioned at heights `4 6 2 1 5`. Elliot can, for instance, prepare the nest at height `1`, then hunt from the nest at height `4`, on the next day hunt from the nest at height `5`, and on the last day hunt from the nest at height `6`:

Note that in this situation, Elliot cannot hunt from the nest at height `6` just after hunting from the nest at height `4`, because these two nests are on the same side of his own nest. Also, after hunting from the rightmost nest, he cannot hunt from the leftmost nest, as it is lower than the previous one. If Elliot chooses the nest at height `6` as their own nest, then he cannot hunt at all, because all other nests are placed lower.

Elliot wonders how many possible ways there are for him to choose their nest and then hunt until he changes places with Eleonora. As the result may be very large, count the number of possibilities modulo 10^{9} + 7 (1,000,000,007).

Write a function:

class Solution { public int solution(int[] H); }

that, given a sequence of heights of nests, returns the remainder from the division by 1,000,000,007 of the number of possible ways for Elliot to choose the nest and hunt.

For example, given:

the function should return 7. All the possible ways for Elliot to choose the nest and hunt are as follows, listed one per line. The first number in each line denotes the height of Elliot's own nest, and each consecutive number describes the height of a nest he will hunt from.

On the other hand, for the following array:

the function should return 23. One of the possible ways Elliot can act is depicted in the figure above.

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

- N is an integer within the range [1..50,000];
- each element of array H is an integer within the range [1..1,000,000,000];
- the elements of H are all distinct.

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

`4 6 2 1 5`. Elliot can, for instance, prepare the nest at height `1`, then hunt from the nest at height `4`, on the next day hunt from the nest at height `5`, and on the last day hunt from the nest at height `6`:

`6` just after hunting from the nest at height `4`, because these two nests are on the same side of his own nest. Also, after hunting from the rightmost nest, he cannot hunt from the leftmost nest, as it is lower than the previous one. If Elliot chooses the nest at height `6` as their own nest, then he cannot hunt at all, because all other nests are placed lower.

^{9} + 7 (1,000,000,007).

Write a function:

func Solution(H []int) int

For example, given:

On the other hand, for the following array:

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

- N is an integer within the range [1..50,000];
- each element of array H is an integer within the range [1..1,000,000,000];
- the elements of H are all distinct.

`4 6 2 1 5`. Elliot can, for instance, prepare the nest at height `1`, then hunt from the nest at height `4`, on the next day hunt from the nest at height `5`, and on the last day hunt from the nest at height `6`:

`6` just after hunting from the nest at height `4`, because these two nests are on the same side of his own nest. Also, after hunting from the rightmost nest, he cannot hunt from the leftmost nest, as it is lower than the previous one. If Elliot chooses the nest at height `6` as their own nest, then he cannot hunt at all, because all other nests are placed lower.

^{9} + 7 (1,000,000,007).

Write a function:

class Solution { public int solution(int[] H); }

For example, given:

On the other hand, for the following array:

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

- N is an integer within the range [1..50,000];
- each element of array H is an integer within the range [1..1,000,000,000];
- the elements of H are all distinct.

`4 6 2 1 5`. Elliot can, for instance, prepare the nest at height `1`, then hunt from the nest at height `4`, on the next day hunt from the nest at height `5`, and on the last day hunt from the nest at height `6`:

`6` just after hunting from the nest at height `4`, because these two nests are on the same side of his own nest. Also, after hunting from the rightmost nest, he cannot hunt from the leftmost nest, as it is lower than the previous one. If Elliot chooses the nest at height `6` as their own nest, then he cannot hunt at all, because all other nests are placed lower.

^{9} + 7 (1,000,000,007).

Write a function:

function solution(H)

For example, given:

On the other hand, for the following array:

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

- N is an integer within the range [1..50,000];
- each element of array H is an integer within the range [1..1,000,000,000];
- the elements of H are all distinct.

Note: All arrays in this task are zero-indexed, unlike the common Lua convention. You can use `#A` to get the length of the array A.

`4 6 2 1 5`. Elliot can, for instance, prepare the nest at height `1`, then hunt from the nest at height `4`, on the next day hunt from the nest at height `5`, and on the last day hunt from the nest at height `6`:

`6` just after hunting from the nest at height `4`, because these two nests are on the same side of his own nest. Also, after hunting from the rightmost nest, he cannot hunt from the leftmost nest, as it is lower than the previous one. If Elliot chooses the nest at height `6` as their own nest, then he cannot hunt at all, because all other nests are placed lower.

^{9} + 7 (1,000,000,007).

Write a function:

int solution(NSMutableArray *H);

For example, given:

On the other hand, for the following array:

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

- N is an integer within the range [1..50,000];
- each element of array H is an integer within the range [1..1,000,000,000];
- the elements of H are all distinct.

`4 6 2 1 5`. Elliot can, for instance, prepare the nest at height `1`, then hunt from the nest at height `4`, on the next day hunt from the nest at height `5`, and on the last day hunt from the nest at height `6`:

`6` just after hunting from the nest at height `4`, because these two nests are on the same side of his own nest. Also, after hunting from the rightmost nest, he cannot hunt from the leftmost nest, as it is lower than the previous one. If Elliot chooses the nest at height `6` as their own nest, then he cannot hunt at all, because all other nests are placed lower.

^{9} + 7 (1,000,000,007).

Write a function:

function solution(H: array of longint; N: longint): longint;

For example, given:

On the other hand, for the following array:

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

- N is an integer within the range [1..50,000];
- each element of array H is an integer within the range [1..1,000,000,000];
- the elements of H are all distinct.

`4 6 2 1 5`. Elliot can, for instance, prepare the nest at height `1`, then hunt from the nest at height `4`, on the next day hunt from the nest at height `5`, and on the last day hunt from the nest at height `6`:

`6` just after hunting from the nest at height `4`, because these two nests are on the same side of his own nest. Also, after hunting from the rightmost nest, he cannot hunt from the leftmost nest, as it is lower than the previous one. If Elliot chooses the nest at height `6` as their own nest, then he cannot hunt at all, because all other nests are placed lower.

^{9} + 7 (1,000,000,007).

Write a function:

function solution($H);

For example, given:

On the other hand, for the following array:

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

- N is an integer within the range [1..50,000];
- each element of array H is an integer within the range [1..1,000,000,000];
- the elements of H are all distinct.

`4 6 2 1 5`. Elliot can, for instance, prepare the nest at height `1`, then hunt from the nest at height `4`, on the next day hunt from the nest at height `5`, and on the last day hunt from the nest at height `6`:

`6` just after hunting from the nest at height `4`, because these two nests are on the same side of his own nest. Also, after hunting from the rightmost nest, he cannot hunt from the leftmost nest, as it is lower than the previous one. If Elliot chooses the nest at height `6` as their own nest, then he cannot hunt at all, because all other nests are placed lower.

^{9} + 7 (1,000,000,007).

Write a function:

sub solution { my (@H)=@_; ... }

For example, given:

On the other hand, for the following array:

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

- N is an integer within the range [1..50,000];
- each element of array H is an integer within the range [1..1,000,000,000];
- the elements of H are all distinct.

`4 6 2 1 5`. Elliot can, for instance, prepare the nest at height `1`, then hunt from the nest at height `4`, on the next day hunt from the nest at height `5`, and on the last day hunt from the nest at height `6`:

`6` just after hunting from the nest at height `4`, because these two nests are on the same side of his own nest. Also, after hunting from the rightmost nest, he cannot hunt from the leftmost nest, as it is lower than the previous one. If Elliot chooses the nest at height `6` as their own nest, then he cannot hunt at all, because all other nests are placed lower.

^{9} + 7 (1,000,000,007).

Write a function:

def solution(H)

For example, given:

On the other hand, for the following array:

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

- N is an integer within the range [1..50,000];
- each element of array H is an integer within the range [1..1,000,000,000];
- the elements of H are all distinct.

`4 6 2 1 5`. Elliot can, for instance, prepare the nest at height `1`, then hunt from the nest at height `4`, on the next day hunt from the nest at height `5`, and on the last day hunt from the nest at height `6`:

`6` just after hunting from the nest at height `4`, because these two nests are on the same side of his own nest. Also, after hunting from the rightmost nest, he cannot hunt from the leftmost nest, as it is lower than the previous one. If Elliot chooses the nest at height `6` as their own nest, then he cannot hunt at all, because all other nests are placed lower.

^{9} + 7 (1,000,000,007).

Write a function:

def solution(h)

For example, given:

On the other hand, for the following array:

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

- N is an integer within the range [1..50,000];
- each element of array H is an integer within the range [1..1,000,000,000];
- the elements of H are all distinct.

`4 6 2 1 5`. Elliot can, for instance, prepare the nest at height `1`, then hunt from the nest at height `4`, on the next day hunt from the nest at height `5`, and on the last day hunt from the nest at height `6`:

`6` just after hunting from the nest at height `4`, because these two nests are on the same side of his own nest. Also, after hunting from the rightmost nest, he cannot hunt from the leftmost nest, as it is lower than the previous one. If Elliot chooses the nest at height `6` as their own nest, then he cannot hunt at all, because all other nests are placed lower.

^{9} + 7 (1,000,000,007).

Write a function:

public func solution(inout H : [Int]) -> Int

For example, given:

On the other hand, for the following array:

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

- N is an integer within the range [1..50,000];
- each element of array H is an integer within the range [1..1,000,000,000];
- the elements of H are all distinct.

`4 6 2 1 5`. Elliot can, for instance, prepare the nest at height `1`, then hunt from the nest at height `4`, on the next day hunt from the nest at height `5`, and on the last day hunt from the nest at height `6`:

`6` just after hunting from the nest at height `4`, because these two nests are on the same side of his own nest. Also, after hunting from the rightmost nest, he cannot hunt from the leftmost nest, as it is lower than the previous one. If Elliot chooses the nest at height `6` as their own nest, then he cannot hunt at all, because all other nests are placed lower.

^{9} + 7 (1,000,000,007).

Write a function:

public func solution(_ H : inout [Int]) -> Int

For example, given:

On the other hand, for the following array:

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

- N is an integer within the range [1..50,000];
- each element of array H is an integer within the range [1..1,000,000,000];
- the elements of H are all distinct.

`4 6 2 1 5`. Elliot can, for instance, prepare the nest at height `1`, then hunt from the nest at height `4`, on the next day hunt from the nest at height `5`, and on the last day hunt from the nest at height `6`:

`6` just after hunting from the nest at height `4`, because these two nests are on the same side of his own nest. Also, after hunting from the rightmost nest, he cannot hunt from the leftmost nest, as it is lower than the previous one. If Elliot chooses the nest at height `6` as their own nest, then he cannot hunt at all, because all other nests are placed lower.

^{9} + 7 (1,000,000,007).

Write a function:

Private Function solution(H As Integer()) As Integer

For example, given:

On the other hand, for the following array:

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

- N is an integer within the range [1..50,000];
- each element of array H is an integer within the range [1..1,000,000,000];
- the elements of H are all distinct.

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