Statistics

Problem Statement for "ListOps"

Problem Statement

Given a list of numbers you will get all of the unique unordered pairs that are not of the form (x,x) (i.e. (1,1) isn't allowed). Since these pairs are unordered (a,b) and (b,a) are the same pair and do not count twice (e.g. (1,2) and (2,1) are the same pair and only count as one pair). For example: numbers = {1,2,3}
Then the pairs are (1,2),(1,3),(2,3). Also:

numbers = {1,3,2,1,3,2} Then the pairs are still (1,2),(1,3),(2,3).

Then your method will return how many unique unordered pairs will either multiply, add, divide, or subtract to produce a value in the list. You must abide by these rules:
- When considering a pair like (2,3) the operands of the operation may be in any order (i.e. you can try 2-3 and 3-2)
- Division is real division, so 3/2 = 1.5
- Division by 0 will never produce a number in the list

numbers = {1,2,3}
(1,2) : 1+2 = 3 (note that 1*2 is also an element, but we only count the pair once)
(1,3) : 3/1 = 3
(2,3) : 3-2 = 1
Three of the pairs can produce values in the list, so your method would return 3.

Create a class ListOps that contains the method howMany, which takes an int[] numbers and returns an int representing how many pairs of numbers can be used to produce other numbers in the list.

Definition

Class:
ListOps
Method:
howMany
Parameters:
int[]
Returns:
int
Method signature:
int howMany(int[] numbers)
(be sure your method is public)

Constraints

  • numbers will contain between 2 and 50 elements, inclusive.
  • Each element of numbers will be between -10000 and 10000, inclusive.

Examples

  1. {1, 2, 3}

    Returns: 3

    This is the example from above.

  2. {3, 2}

    Returns: 0

    There is no possible way to produce any element of the list.

  3. {-1000, 0, -500, 23, 4000, 9000, 1231, 23}

    Returns: 7

  4. {14, 0, 1239, -10, -10000, 10000, 9999}

    Returns: 7

  5. {0, 1, 0}

    Returns: 1

  6. {1, 2, 3, 1, 3, 2}

    Returns: 3

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

    Returns: 6

  8. {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49}

    Returns: 1225

  9. {10000, 9999, 9998, 9997, 9996, 9995, 9994, 9993, 9992, 9991, 9990, -10000, -9999, -9998, -9997, -9996, -9995, -9996, -9995, -9994, -9993, -9992, -9991, -9990, 10000, 9999, 9998, 9997, 9996, 9995, 9996, 9995, 9994, 9993, 9992, 9991, 9990, -10000, -9999, -9998, -9997, -9996, -9995, -9996, -9995, -9994, -9993, -9992, -9991, -9990}

    Returns: 0

  10. {1000, 500, 2, 501}

    Returns: 3

  11. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

    Returns: 0

  12. {0, 0}

    Returns: 0

  13. {0, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 18, 24, 30, 32, 40, 50, 80, 0, -1, -2, -3, -4, -5, -6, -8, -10, -12, -15, 192}

    Returns: 288

  14. {10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1}

    Returns: 210

  15. {10000, 5000, 2, 9999, -9, 1111, -4, 8, -5, 10, -6, 12, -7, 14, -8, 16, -9, 18}

    Returns: 54

  16. {6, 5, 1}

    Returns: 3

  17. {14, 0, 1239, -10, -10000, 10000, 9999}

    Returns: 7

  18. {4, 17}

    Returns: 0

  19. {-10, -5, 2}

    Returns: 3

  20. {0, 100, -100, -4, 3, 2, 33, -2, -10, -1, -1, -2, 0, 0, 33}

    Returns: 22

  21. {-2, -3, 6}

    Returns: 3

  22. {2, 3, 7}

    Returns: 0

  23. {0, -100, 100, -3, -4, -5, 2, 2, 4, 4, -100, 1, 1, 1}

    Returns: 24

  24. {-1000, 0, -500, 23, 4000, 9000, 1231, 23}

    Returns: 7

  25. {-1000, 500, -2}

    Returns: 3

  26. {0, 1, 2, 3}

    Returns: 6

  27. {-1000, -500, 23, -23, 0, -46}

    Returns: 9

  28. {14, 0, 1239, -10, -10000, 10000, 9999}

    Returns: 7

  29. {-10, 0, 10, -10, -20}

    Returns: 6

  30. {2, 100, 200}

    Returns: 3

  31. {5, 1, 0}

    Returns: 3

  32. {14, 0, 1239, -10, -10000, 10000, 9999}

    Returns: 7

  33. {1, 2, 3, 1}

    Returns: 3

  34. {1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 0}

    Returns: 45

  35. {2, 1, 0}

    Returns: 3

  36. {1, 3, 4, 1, 1, 2, 3, 134}

    Returns: 7

  37. {2, 3, 6}

    Returns: 3

  38. {1, 33, 44}

    Returns: 2

  39. {2, 11, 23}

    Returns: 0

  40. {14, 0, 1239, -10, -10000, 10000, 9999}

    Returns: 7

  41. {3, -3, -1}

    Returns: 3

  42. {-10000, 14, 0, 1239, -10, -10000, 10000, 9999, 0, 9998, 9997, 9998, 2, 7, -17, -13, 0, 0, 0, 9, -10000, 14, 0, 1239, -10, -10000, 10000, 9999, 0, 9998, 9997, 9998, 2, 7, -17, -13, 0, 0, 0, 9, -10000, 14, 0, 1239, -10, -10000, 10000, 9999, 0, 4}

    Returns: 36

  43. {1, 2, 3, 4}

    Returns: 6


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: