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

Given points on a plane, count the number of sets of four points that form regular diamonds.

Spoken language:

A *diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

You are given N distinct points on a plane. Count the number of different diamonds that can be constructed using these points as vertices (two diamonds are different if their sets of vertices are different). Do not count diamonds whose area is empty.

Write a function:

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

that, given two arrays X and Y, each containing N integers, representing N points (where X[K], Y[K] are the coordinates of the K-th point), returns the number of diamonds on the plane.

For example, for N = 7 points whose coordinates are specified in arrays X = [1, 1, 2, 2, 2, 3, 3] and Y = [3, 4, 1, 3, 5, 3, 4], the function should return 2, since we can find two diamonds as shown in the picture below:

Given arrays: X = [1, 2, 3, 3, 2, 1], Y = [1, 1, 1, 2, 2, 2], the function should return 0, since there are no diamonds on the plane:

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

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

A *diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

You are given N distinct points on a plane. Count the number of different diamonds that can be constructed using these points as vertices (two diamonds are different if their sets of vertices are different). Do not count diamonds whose area is empty.

Write a function:

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

that, given two arrays X and Y, each containing N integers, representing N points (where X[K], Y[K] are the coordinates of the K-th point), returns the number of diamonds on the plane.

For example, for N = 7 points whose coordinates are specified in arrays X = [1, 1, 2, 2, 2, 3, 3] and Y = [3, 4, 1, 3, 5, 3, 4], the function should return 2, since we can find two diamonds as shown in the picture below:

Given arrays: X = [1, 2, 3, 3, 2, 1], Y = [1, 1, 1, 2, 2, 2], the function should return 0, since there are no diamonds on the plane:

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

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

A *diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

You are given N distinct points on a plane. Count the number of different diamonds that can be constructed using these points as vertices (two diamonds are different if their sets of vertices are different). Do not count diamonds whose area is empty.

Write a function:

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

that, given two arrays X and Y, each containing N integers, representing N points (where X[K], Y[K] are the coordinates of the K-th point), returns the number of diamonds on the plane.

For example, for N = 7 points whose coordinates are specified in arrays X = [1, 1, 2, 2, 2, 3, 3] and Y = [3, 4, 1, 3, 5, 3, 4], the function should return 2, since we can find two diamonds as shown in the picture below:

Given arrays: X = [1, 2, 3, 3, 2, 1], Y = [1, 1, 1, 2, 2, 2], the function should return 0, since there are no diamonds on the plane:

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

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

*diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

Write a function:

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

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

*diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

Write a function:

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

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

*diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

Write a function:

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

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

*diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

Write a function:

function solution(X, Y);

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

*diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

Write a function:

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

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

*diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

Write a function:

function solution(X, Y)

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise 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.

*diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

Write a function:

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

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

*diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

Write a function:

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

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

*diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

Write a function:

function solution($X, $Y);

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

*diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

Write a function:

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

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

*diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

Write a function:

def solution(X, Y)

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

*diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

Write a function:

def solution(x, y)

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

*diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

Write a function:

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

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

*diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

Write a function:

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

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.

*diamond* is a quadrilateral whose four sides all have the same length and whose diagonals are parallel to the coordinate axes.

Write a function:

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

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

- N is an integer within the range [4..1,500];
- each element of arrays X, Y is an integer within the range [0..N−1];
- given N points are pairwise distinct.