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

AVAILABLE LESSONS:

Lesson 1

Iterations

Lesson 2

Arrays

Lesson 3

Time Complexity

Lesson 4

Counting Elements

Lesson 5

Prefix Sums

Lesson 6

Sorting

Lesson 7

Stacks and Queues

Lesson 8

Leader

Lesson 9

Maximum slice problem

Lesson 10

Prime and composite numbers

Lesson 11

Sieve of Eratosthenes

Lesson 12

Euclidean algorithm

Lesson 13

Fibonacci numbers

Lesson 14

Binary search algorithm

Lesson 15

Caterpillar method

Lesson 16

Greedy algorithms

Lesson 17

Dynamic programming

Lesson 90

Tasks from Indeed Prime 2015 challenge

Lesson 91

Tasks from Indeed Prime 2016 challenge

Lesson 92

Tasks from Indeed Prime 2016 College Coders challenge

Lesson 99

Future training

Find the earliest time when a frog can jump to the other side of a river.

Spoken language:

A small frog wants to get to the other side of a river. The frog is initially located on one bank of the river (position 0) and wants to get to the opposite bank (position X+1). Leaves fall from a tree onto the surface of the river.

You are given an array A consisting of N integers representing the falling leaves. A[K] represents the position where one leaf falls at time K, measured in seconds.

The goal is to find the earliest time when the frog can jump to the other side of the river. The frog can cross only when leaves appear at every position across the river from 1 to X (that is, we want to find the earliest moment when all the positions from 1 to X are covered by leaves). You may assume that the speed of the current in the river is negligibly small, i.e. the leaves do not change their positions once they fall in the river.

For example, you are given integer X = 5 and array A such that:

In second 6, a leaf falls into position 5. This is the earliest time when leaves appear in every position across the river.

Write a function:

int solution(int X, int A[], int N);

that, given a non-empty array A consisting of N integers and integer X, returns the earliest time when the frog can jump to the other side of the river.

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

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

A small frog wants to get to the other side of a river. The frog is initially located on one bank of the river (position 0) and wants to get to the opposite bank (position X+1). Leaves fall from a tree onto the surface of the river.

You are given an array A consisting of N integers representing the falling leaves. A[K] represents the position where one leaf falls at time K, measured in seconds.

The goal is to find the earliest time when the frog can jump to the other side of the river. The frog can cross only when leaves appear at every position across the river from 1 to X (that is, we want to find the earliest moment when all the positions from 1 to X are covered by leaves). You may assume that the speed of the current in the river is negligibly small, i.e. the leaves do not change their positions once they fall in the river.

For example, you are given integer X = 5 and array A such that:

In second 6, a leaf falls into position 5. This is the earliest time when leaves appear in every position across the river.

Write a function:

int solution(int X, vector<int> &A);

that, given a non-empty array A consisting of N integers and integer X, returns the earliest time when the frog can jump to the other side of the river.

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

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

A small frog wants to get to the other side of a river. The frog is initially located on one bank of the river (position 0) and wants to get to the opposite bank (position X+1). Leaves fall from a tree onto the surface of the river.

You are given an array A consisting of N integers representing the falling leaves. A[K] represents the position where one leaf falls at time K, measured in seconds.

The goal is to find the earliest time when the frog can jump to the other side of the river. The frog can cross only when leaves appear at every position across the river from 1 to X (that is, we want to find the earliest moment when all the positions from 1 to X are covered by leaves). You may assume that the speed of the current in the river is negligibly small, i.e. the leaves do not change their positions once they fall in the river.

For example, you are given integer X = 5 and array A such that:

In second 6, a leaf falls into position 5. This is the earliest time when leaves appear in every position across the river.

Write a function:

class Solution { public int solution(int X, int[] A); }

that, given a non-empty array A consisting of N integers and integer X, returns the earliest time when the frog can jump to the other side of the river.

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

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

For example, you are given integer X = 5 and array A such that:

Write a function:

func Solution(X int, A []int) int

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

For example, you are given integer X = 5 and array A such that:

Write a function:

class Solution { public int solution(int X, int[] A); }

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

For example, you are given integer X = 5 and array A such that:

Write a function:

class Solution { public int solution(int X, int[] A); }

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

For example, you are given integer X = 5 and array A such that:

Write a function:

function solution(X, A);

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

For example, you are given integer X = 5 and array A such that:

Write a function:

fun solution(X: Int, A: IntArray): Int

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

For example, you are given integer X = 5 and array A such that:

Write a function:

function solution(X, A)

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

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.

For example, you are given integer X = 5 and array A such that:

Write a function:

int solution(int X, NSMutableArray *A);

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

For example, you are given integer X = 5 and array A such that:

Write a function:

function solution(X: longint; A: array of longint; N: longint): longint;

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

For example, you are given integer X = 5 and array A such that:

Write a function:

function solution($X, $A);

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

For example, you are given integer X = 5 and array A such that:

Write a function:

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

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

For example, you are given integer X = 5 and array A such that:

Write a function:

def solution(X, A)

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

For example, you are given integer X = 5 and array A such that:

Write a function:

def solution(x, a)

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

For example, you are given integer X = 5 and array A such that:

Write a function:

object Solution { def solution(x: Int, a: Array[Int]): Int }

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

For example, you are given integer X = 5 and array A such that:

Write a function:

public func solution(_ X : Int, _ A : inout [Int]) -> Int

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

For example, you are given integer X = 5 and array A such that:

Write a function:

Private Function solution(X As Integer, A As Integer()) As Integer

If the frog is never able to jump to the other side of the river, the function should return −1.

For example, given X = 5 and array A such that:

the function should return 6, as explained above.

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

- N and X are integers within the range [1..100,000];
- each element of array A is an integer within the range [1..X].

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

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