Connection Status:
Competition Arena > FriendlySequences
TCCC06 Spon 1 · 2006-08-22 · by Cosmin.ro · Brute Force
Class Name: FriendlySequences
Return Type: int
Method Name: count
Arg Types: (vector<int>)
Problem Statement

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 int[] array, you must return number of different friendly contignuous subsequences of array.

Constraints

  • array will have between 0 and 50 elements, inclusive.
  • Each element of array will be between 0 and 2000000000, inclusive.
Examples
0)
{112, 12, 21, 354, 534345, 345, 2221}
Returns: 6

The example in the problem.

1)
{10, 1100, 10101, 111, 1111, 11111, 11, 1, 111}
Returns: 18
2)
{0, 0, 0, 0}
Returns: 6

We have a total of 6 possible different pairs of start and end indices for friendly subsequences.

3)
{123456890, 213456890, 198654320}
Returns: 3
4)
{}
Returns: 0

Submissions are judged against all 77 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

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

Submitting as anonymous