N
N
NikitaWeb2019-09-15 21:44:45
Java
NikitaWeb, 2019-09-15 21:44:45

What is set matching?

You need to write a method that returns a list of dissimilar strings. But first you need to understand what is written in the condition.

An integer matrix is ​​given, in which there are N rows, and the number of elements in a row for each row can be any number, including zero. Rows are called similar if the sets of numbers occurring in these rows coincide. Find a list of rows of this matrix of maximum dimension in which all rows are pairwise dissimilar. From similar lines, include the line with the highest number in the list. The order of the elements in the list is arbitrary.

5d7e87024697a653374906.png
The first 2 lines are similar to each other and unlike the 3rd line. The answer will be a list of 2 and 3 lines.

For example, the method must pass the following tests:
public void testMatrixNonSimilarRows() {
        int[][] matrix1 = {{}, {1, 2, 2, 4, 4}, {4, 2, 1, 4}, {3, 2, 4, 1, 5, 8}, {2, 3, 1, 4, 1, 5, 8}, {1, 8, 1, 1, 8}};
        List<int[]> nonSimilarRows1 = new MatrixNonSimilarRows(matrix1).getNonSimilarRows();
        assertEquals(4, nonSimilarRows1.size());
        assertTrue(nonSimilarRows1.contains(matrix1[0]));
        assertTrue(nonSimilarRows1.contains(matrix1[2]));
        assertTrue(nonSimilarRows1.contains(matrix1[4]));
        assertTrue(nonSimilarRows1.contains(matrix1[5]));
        int[][] matrix2 = {{1, 2, 2, 4, 4}, {4, 5, 1, 4}, {2, 4, 1}, {2, 4, 1, 4, 1, 2}, {1, 8, 1, 1, 8}};
        List<int[]> nonSimilarRows2 = new MatrixNonSimilarRows(matrix2).getNonSimilarRows();
        assertEquals(3, nonSimilarRows2.size());
        assertTrue(nonSimilarRows2.contains(matrix2[1]));
        assertTrue(nonSimilarRows2.contains(matrix2[3]));
        assertTrue(nonSimilarRows2.contains(matrix2[4]));
        int[][] matrix3 = {{}, {}};
        List<int[]> nonSimilarRows3 = new MatrixNonSimilarRows(matrix3).getNonSimilarRows();
        assertEquals(1, nonSimilarRows3.size());
        assertTrue(nonSimilarRows3.contains(matrix3[1]));
    }

Please help me to understand the condition. In particular, what is meant by similar strings in this situation?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
Rsa97, 2019-09-15
@NikitaWeb

For each line, make up the sets of numbers that are present in this line. For your example:
1 2 2 4 4 => [1, 2, 4]
4 2 1 4 => [1, 2, 4]
3 2 4 1 5 8 => [1, 2, 3, 4, 5, 8]
Those rows for which these sets completely coincide (the first and second rows in the example) are considered similar by condition.

M
Mercury13, 2019-09-15
@Mercury13

Sets coincide - this, in fact, are equal as sets. In other words, they are equal if duplicates are eliminated and sorted in some order.
For example, { 1, 2, 3 } = { 3, 3, 2, 1, 2, 1 }.

A
AVKor, 2019-09-15
@AVKor

Here .

X
xmoonlight, 2019-09-18
@xmoonlight

As I understand the condition:
Similar two sets/two rows are those with more than 50% unique elements of the set.
Dissimilar two sets/two strings - having 50% (or less percent) unique elements.
Unlike: create a new cluster.
Similar: Add an element to a similar cluster.
-----------
Answer to "Find a list of rows of this matrix of maximum dimension, in which all rows are pairwise dissimilar to each other.":
12244
324158
Answer to "Include the row with the highest number from similar rows into the list. ":
4214

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question