Statistics

Problem Statement for "SetPartialOrder"

Problem Statement

In math, we sometimes define a partial order on some objects. In this problem we will take a look at one possible way how to define a partial order on sets of integers.

Consider two sets of integers: X and Y. These two sets can be related to each other in four possible ways:

  • X is equal to Y if each element of X is also an element of Y and vice versa.
  • X is less than Y if X is not equal to Y (see previous item) and each element of X is also an element of Y.
  • X is greater than Y if Y is less than X.
  • In all other cases X and Y are incomparable.

In other words: X is less than Y if and only if X is a proper subset of Y. Two sets are incomparable if neither is a subset of the other.

You are given two int[]s a and b. The elements of a form the set X. The elements of b form the set Y. Compare X to Y and return the correct one of the following four strings: "EQUAL", "LESS", "GREATER", or "INCOMPARABLE".

(The string "LESS" means that X is less than Y, the string "GREATER" means that X is greater than Y. Quotes are for clarity only. Note that the return value is case-sensitive.)

Definition

Class:
SetPartialOrder
Method:
compareSets
Parameters:
int[], int[]
Returns:
String
Method signature:
String compareSets(int[] a, int[] b)
(be sure your method is public)

Constraints

  • Each of arrays a and b will have length between 1 and 50, inclusive.
  • Each element of arrays a and b will be between 1 and 100, inclusive.
  • In each of arrays a and b all elements are distinct.

Examples

  1. {1, 2, 3, 5, 8}

    {8, 5, 1, 3, 2}

    Returns: "EQUAL"

    The order of elements in a and b does not matter. The two sets X and Y are equal.

  2. {2, 3, 5, 7}

    {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

    Returns: "LESS"

    Each number that occurs in a does also occur in b.

  3. {2, 4, 6, 8, 10, 12, 14, 16}

    {2, 4, 8, 16}

    Returns: "GREATER"

  4. {42, 23, 17}

    {15, 23, 31}

    Returns: "INCOMPARABLE"

  5. {1}

    {1}

    Returns: "EQUAL"

  6. {5}

    {4}

    Returns: "INCOMPARABLE"

  7. {100}

    {95}

    Returns: "INCOMPARABLE"

  8. {4, 5, 6}

    {9, 1, 4}

    Returns: "INCOMPARABLE"

  9. {2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98}

    {2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98}

    Returns: "EQUAL"

  10. {2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98}

    {1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99}

    Returns: "INCOMPARABLE"

  11. {1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99}'

    {51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99}

    Returns: "INCOMPARABLE"

  12. {1 }

    {2, 3, 4 }

    Returns: "INCOMPARABLE"

  13. {1, 2, 3 }

    {1, 4, 5, 6 }

    Returns: "INCOMPARABLE"

  14. {2, 3 }

    {4, 1 }

    Returns: "INCOMPARABLE"

  15. {42, 23, 17, 50 }

    {15, 23, 31 }

    Returns: "INCOMPARABLE"

  16. {1, 2, 3, 5, 8 }

    {1 }

    Returns: "GREATER"

  17. {1, 2 }

    {2, 3, 4 }

    Returns: "INCOMPARABLE"

  18. {3, 4, 5 }

    {1, 2 }

    Returns: "INCOMPARABLE"

  19. {1, 2, 3, 5, 8 }

    {8, 5, 1, 3, 2 }

    Returns: "EQUAL"

  20. {1, 2 }

    {1, 2 }

    Returns: "EQUAL"

  21. {2, 3, 5, 15 }

    {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }

    Returns: "INCOMPARABLE"

  22. {2, 4, 6, 8, 10, 12, 14, 16 }

    {2, 4, 8, 16 }

    Returns: "GREATER"

  23. {2, 3, 5, 7 }

    {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }

    Returns: "LESS"

  24. {1, 2, 4, 7, 8 }

    {1, 4, 3 }

    Returns: "INCOMPARABLE"

  25. {100, 99 }

    {99, 88 }

    Returns: "INCOMPARABLE"

  26. {1, 2, 3, 4, 5, 6, 7, 8 }

    {13 }

    Returns: "INCOMPARABLE"

  27. {1, 2, 3 }

    {1, 2 }

    Returns: "GREATER"

  28. {1, 2, 3 }

    {4, 5 }

    Returns: "INCOMPARABLE"

  29. {1, 2, 3, 5, 8, 100 }

    {8, 5, 1, 3, 2, 100, 99 }

    Returns: "LESS"

  30. {1, 100 }

    {8, 5, 1, 3, 2 }

    Returns: "INCOMPARABLE"

  31. {1, 2, 3, 7, 6, 9 }

    {8, 5, 1, 3, 2 }

    Returns: "INCOMPARABLE"

  32. {1, 2, 3, 5 }

    {2, 4, 8, 9, 11 }

    Returns: "INCOMPARABLE"

  33. {2, 3, 4, 5, 6, 7, 8 }

    {13 }

    Returns: "INCOMPARABLE"

  34. {1, 3, 4 }

    {1, 2 }

    Returns: "INCOMPARABLE"

  35. {1, 2 }

    {3 }

    Returns: "INCOMPARABLE"

  36. {2, 4, 6, 8 }

    {2, 4, 6 }

    Returns: "GREATER"

  37. {42, 23, 17 }

    {15, 23, 31 }

    Returns: "INCOMPARABLE"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: