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

Spoken language:

The Fibonacci sequence is defined using the following recursive formula:

A small frog wants to get to the other side of a river. The frog is initially located at one bank of the river (position −1) and wants to get to the other bank (position N). The frog can jump over any distance F(K), where F(K) is the K-th Fibonacci number. Luckily, there are many leaves on the river, and the frog can jump between the leaves, but only in the direction of the bank at position N.

The leaves on the river are represented in an array A consisting of N integers. Consecutive elements of array A represent consecutive positions from 0 to N − 1 on the river. Array A contains only 0s and/or 1s:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

The goal is to count the minimum number of jumps in which the frog can get to the other side of the river (from position −1 to position N). The frog can jump between positions −1 and N (the banks of the river) and every position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

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

that, given an array A consisting of N integers, returns the minimum number of jumps by which the frog can get to the other side of the river. If the frog cannot reach the other side of the river, the function should return −1.

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

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

The Fibonacci sequence is defined using the following recursive formula:

A small frog wants to get to the other side of a river. The frog is initially located at one bank of the river (position −1) and wants to get to the other bank (position N). The frog can jump over any distance F(K), where F(K) is the K-th Fibonacci number. Luckily, there are many leaves on the river, and the frog can jump between the leaves, but only in the direction of the bank at position N.

The leaves on the river are represented in an array A consisting of N integers. Consecutive elements of array A represent consecutive positions from 0 to N − 1 on the river. Array A contains only 0s and/or 1s:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

The goal is to count the minimum number of jumps in which the frog can get to the other side of the river (from position −1 to position N). The frog can jump between positions −1 and N (the banks of the river) and every position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

int solution(vector<int> &A);

that, given an array A consisting of N integers, returns the minimum number of jumps by which the frog can get to the other side of the river. If the frog cannot reach the other side of the river, the function should return −1.

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

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

The Fibonacci sequence is defined using the following recursive formula:

A small frog wants to get to the other side of a river. The frog is initially located at one bank of the river (position −1) and wants to get to the other bank (position N). The frog can jump over any distance F(K), where F(K) is the K-th Fibonacci number. Luckily, there are many leaves on the river, and the frog can jump between the leaves, but only in the direction of the bank at position N.

The leaves on the river are represented in an array A consisting of N integers. Consecutive elements of array A represent consecutive positions from 0 to N − 1 on the river. Array A contains only 0s and/or 1s:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

The goal is to count the minimum number of jumps in which the frog can get to the other side of the river (from position −1 to position N). The frog can jump between positions −1 and N (the banks of the river) and every position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

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

that, given an array A consisting of N integers, returns the minimum number of jumps by which the frog can get to the other side of the river. If the frog cannot reach the other side of the river, the function should return −1.

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

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

The Fibonacci sequence is defined using the following recursive formula:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

func Solution(A []int) int

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

The Fibonacci sequence is defined using the following recursive formula:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

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

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

The Fibonacci sequence is defined using the following recursive formula:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

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

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

The Fibonacci sequence is defined using the following recursive formula:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

function solution(A);

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

The Fibonacci sequence is defined using the following recursive formula:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

fun solution(A: IntArray): Int

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

The Fibonacci sequence is defined using the following recursive formula:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

function solution(A)

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

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.

The Fibonacci sequence is defined using the following recursive formula:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

int solution(NSMutableArray *A);

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

The Fibonacci sequence is defined using the following recursive formula:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

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

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

The Fibonacci sequence is defined using the following recursive formula:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

function solution($A);

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

The Fibonacci sequence is defined using the following recursive formula:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

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

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

The Fibonacci sequence is defined using the following recursive formula:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

def solution(A)

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

The Fibonacci sequence is defined using the following recursive formula:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

def solution(a)

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

The Fibonacci sequence is defined using the following recursive formula:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

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

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

The Fibonacci sequence is defined using the following recursive formula:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

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

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.

The Fibonacci sequence is defined using the following recursive formula:

- 0 represents a position without a leaf;
- 1 represents a position containing a leaf.

For example, consider array A such that:

The frog can make three jumps of length F(5) = 5, F(3) = 2 and F(5) = 5.

Write a function:

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

For example, given:

the function should return 3, as explained above.

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

- N is an integer within the range [0..100,000];
- each element of array A is an integer that can have one of the following values: 0, 1.