Statistics

Problem Statement for "RelationClassifier"

Problem Statement

Weiwei is studying math. Unfortunately, math is very hard for him. Today, the teacher asked Weiwei to determine if a relation is a bijection or not.

Formally, a relation is a set of ordered pairs of elements. The teacher gave Weiwei one such relation. You are also given a description of this relation: int[]s domain and range. For each valid i, the relation contains the ordered pair (domain[i], range[i]).

Let X be the set of elements that appear at least once in domain. Similarly, let Y be the set of elements that appear at least once in range. We say that an element x of X is paired to an element y of Y if the relation contains the ordered pair (x, y).

We will say that our relation is a bijection if each element of X is paired to exactly one element of Y, and each element of Y is paired to exactly one element of X.

If Weiwei's relation is a bijection, return "Bijection" (quotes for clarity). Otherwise, return "Not". Note that the return value is case-sensitive.

Definition

Class:
RelationClassifier
Method:
isBijection
Parameters:
int[], int[]
Returns:
String
Method signature:
String isBijection(int[] domain, int[] range)
(be sure your method is public)

Constraints

  • domain will contain between 1 and 10 elements, inclusive.
  • range will contain the same number of elements as domain.
  • Each element of domain and range will be between 1 and 100, inclusive.
  • No two pairs (domain[i], range[i]) will be identical.

Examples

  1. {1, 1}

    {2, 3}

    Returns: "Not"

    Since 1 in X is paired with both 2 and 3 in Y, the given relation is not a bijection.

  2. {4, 5}

    {2, 2}

    Returns: "Not"

    Since both 4 and 5 in X are paired with 2 in Y, the given relation is not a bijection.

  3. {1}

    {2}

    Returns: "Bijection"

    A single ordered pair is always a bijection.

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

    {1, 2, 3, 4, 5}

    Returns: "Bijection"

  5. {14, 12, 10, 13, 20, 18, 9, 17, 14, 9}

    {18, 6, 8, 15, 2, 14, 10, 13, 13, 15}

    Returns: "Not"

  6. {2}

    {30}

    Returns: "Bijection"

  7. {2,2}

    {2,1}

    Returns: "Not"

  8. {2,1,3}

    {3,4,2}

    Returns: "Bijection"

  9. {4,6,1,1}

    {1,1,1,5}

    Returns: "Not"

  10. {15,2,18,18,9}

    {3,1,4,1,4}

    Returns: "Not"

  11. {5,3,7,3,8}

    {6,13,9,14,9}

    Returns: "Not"

  12. {16,9,7,16,12}

    {20,1,1,19,14}

    Returns: "Not"

  13. {18,68,51,64,64,21}

    {8,71,60,24,48,40}

    Returns: "Not"

  14. {3,19,6,7,8,1,25}

    {8,17,26,17,2,28,4}

    Returns: "Not"

  15. {35,25,24,49,7,48,37,44}

    {38,18,5,1,45,48,9,41}

    Returns: "Bijection"

  16. {1,8,7,4,10,3,7,3,2}

    {7,3,7,8,9,2,6,5,8}

    Returns: "Not"

  17. {18,8,50,3,33,2,87,100,1,23}

    {29,58,83,31,75,95,29,34,58,62}

    Returns: "Not"

  18. {92,99,96,95,82,58,84,47,47,10}

    {82,44,5,82,29,62,98,49,19,30}

    Returns: "Not"

  19. {5,53,23,57,83,14,90,25,42,94}

    {13,48,76,72,33,55,91,65,61,4}

    Returns: "Bijection"

  20. {100,100,100,100,100,100,100,100,100,100}

    {91,92,93,94,95,96,97,98,99,100}

    Returns: "Not"

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

    {100,100,100,100,100,100,100,100,100,100}

    Returns: "Not"

  22. {50,51,52,53,54,55,56,57,58,59}

    {50,49,48,47,46,45,44,43,42,41}

    Returns: "Bijection"

  23. {57,98,14,75,78,20,27,35,96,13}

    {10,87,94,49,52,97,41,12,36,27}

    Returns: "Bijection"

  24. {97,32,50,38,87,2,84,18,8,59}

    {93,43,96,11,45,14,17,69,63,25}

    Returns: "Bijection"

  25. {94,74,71,86,46,22,23,50,58,14}

    {11,100,44,96,81,31,89,27,92,77}

    Returns: "Bijection"

  26. {14, 12, 10, 13, 20, 18, 9, 17, 14, 9 }

    {18, 6, 8, 15, 2, 14, 10, 13, 13, 15 }

    Returns: "Not"

  27. {1, 2 }

    {2, 2 }

    Returns: "Not"

  28. {1, 1 }

    {2, 3 }

    Returns: "Not"

  29. {1, 2, 3, 4, 5 }

    {1, 2, 3, 4, 5 }

    Returns: "Bijection"

  30. {1, 2 }

    {3, 4 }

    Returns: "Bijection"

  31. {1, 5 }

    {2, 3 }

    Returns: "Bijection"

  32. {1, 1, 2 }

    {1, 2, 1 }

    Returns: "Not"

  33. {1, 1, 2 }

    {2, 3, 3 }

    Returns: "Not"

  34. {100 }

    {17 }

    Returns: "Bijection"

  35. {1 }

    {1 }

    Returns: "Bijection"

  36. {100, 100 }

    {1, 2 }

    Returns: "Not"

  37. {3, 2, 1 }

    {1, 2, 3 }

    Returns: "Bijection"

  38. {1, 2, 1 }

    {2, 4, 3 }

    Returns: "Not"

  39. {1, 2 }

    {2, 1 }

    Returns: "Bijection"

  40. {1, 1, 2, 2, 3, 3 }

    {1, 2, 1, 3, 2, 3 }

    Returns: "Not"

  41. {5, 4, 3, 2, 1 }

    {1, 2, 3, 4, 5 }

    Returns: "Bijection"

  42. {1, 2, 3 }

    {3, 2, 1 }

    Returns: "Bijection"

  43. {1, 2, 3, 4, 5, 5 }

    {1, 2, 3, 4, 5, 6 }

    Returns: "Not"

  44. {1, 2, 1, 2 }

    {3, 4, 4, 3 }

    Returns: "Not"

  45. {1, 2, 3 }

    {1, 1, 1 }

    Returns: "Not"


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: