FriendlySequences
TCCC06 Spon 1 · 2006-08-22 · by Cosmin.ro
Problem Statement
We call two numbers friendly if they have the same digits, ignoring order or repetition. For example 122213 and 312 are friendly while 145 and 2544411 are not. A sequence is friendly if it contains at least two numbers, and all possible pairs of numbers within it are friendly. Two contiguous subsequences are different if they have a different start index, end index or both.
If we are given the sequence 112, 12, 21, 354, 534345, 345, 2221 then the friendly contiguous subsequences are: {112, 12}, {112, 12, 21}, {12, 21}, {354, 534345}, {354, 534345, 345} and {534345, 345}. {112, 12, 21, 354} is not a friendly contiguous subsequence because 112 and 354 are not friendly numbers and {112, 12, 21, 2221} is not a friendly contignuous subsequence because the elements of the sequence aren't in consecutive positions in the original sequence.
Given a
Constraints
- array will have between 0 and 50 elements, inclusive.
- Each element of array will be between 0 and 2000000000, inclusive.
{112, 12, 21, 354, 534345, 345, 2221}
Returns: 6
The example in the problem.
{10, 1100, 10101, 111, 1111, 11111, 11, 1, 111}
Returns: 18
{0, 0, 0, 0}
Returns: 6
We have a total of 6 possible different pairs of start and end indices for friendly subsequences.
{123456890, 213456890, 198654320}
Returns: 3
{}
Returns: 0
Submissions are judged against all 77 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class FriendlySequences with a public method int count(vector<int> array) · 77 test cases · 2 s / 256 MB per case