sorting

A collection of 4 post

Triangle

Problem An array A consisting of N integers is given. A triplet (P, Q, R) is triangular if 0 ≤ P < Q < R < N and: For example, consider array A such that: Triplet (0, 2, 4) is triangular. Write a function: that, given an array A consisting of N integers, returns 1 if there exists a triangular…

Number of Disc Intersection

Problem We draw N discs on a plane. The discs are numbered from 0 to N − 1. An array A of N non-negative integers, specifying the radiuses of the discs, is given. The J-th disc is drawn with its center at (J, 0) and radius AJ. We say that the J-th disc and K-th disc intersect if J ≠ K and the J-th…

Max Product Of Three

Problem A non-empty array A consisting of N integers is given. The product of triplet (P, Q, R) equates to AP _ AQ _ AR (0 ≤ P < Q < R < N). For example, array A such that: contains the following example triplets: (0, 1, 2), product is −3 _ 1 _ 2 = −6 (1, 2, 4), product is 1 _ 2 _ 5 = 10 (2, 4,…

Distinct

Problem Write a function that, given an array A consisting of N integers, returns the number of distinct values in array A. For example, given array A consisting of six elements such that: the function should return 3, because there are 3 distinct values appearing in array A, namely 1, 2 and…