Problem Statement
The prince has just been introduced to primitive pythagorean triplets.
A primitive pythagorean triplet (a, b, c) is a triplet satisfying the following properties:
You are given a String[] stick. Concatenate the elements of stick to get a single-space separated list of the lengths of available sticks. The king is a very loving father and would like to make the toys with his own hands. However, he is not skilled enough to cut the sticks, so he must use them in the sizes they are available. Return the maximum possible number of toys the king can make using these sticks.
A primitive pythagorean triplet (a, b, c) is a triplet satisfying the following properties:
- a, b and c are integers
- a^2 + b^2 = c^2
- The greatest common divisor of a and b is 1
You are given a String[] stick. Concatenate the elements of stick to get a single-space separated list of the lengths of available sticks. The king is a very loving father and would like to make the toys with his own hands. However, he is not skilled enough to cut the sticks, so he must use them in the sizes they are available. Return the maximum possible number of toys the king can make using these sticks.
Definition
- Class:
- PythTriplets
- Method:
- findMax
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int findMax(String[] stick)
- (be sure your method is public)
Notes
- An integer may be listed multiple times in the String formed by the concatenation of stick . If an integer n is listed k times, then the king has exactly k sticks of length n available with him.
Constraints
- stick will contain between 1 and 50 elements, inclusive.
- Each element of stick will contain between 1 and 50 characters, inclusive.
- When concatenated, stick will represent a single-space separated list of N integers, where N is between 1 and 200 inclusive.
- Each listed integer will be between 1 and 999999, inclusive.
- Listed integers will not have leading zeroes.
Examples
{"3 4 4 3 11 5 12 9 4"}Returns: 3
(3, 4, 5) and (5, 12, 13) are primitive pythagorean triplets. Hence, there are three disjoint pairs (a, b) - (3, 4), (3, 4) and (5, 12).{"20 21 3021 220"}Returns: 2
Possible pairs (a, b) are (20, 21), (21, 220) and (220, 3021). The maximum number of disjoint pairs is 2. Namely, (20, 21) and (220, 3021).{"28 19", "5 1035 21412 37995"}Returns: 2
Make sure you concatenate the elements of stick.