def test_large_range(self):
    n = 100000

    expected, array = self.__get_random_input_and_solution(n)
    with self.subTest(solution=expected, n=n):
      self.assertEqual(get_missing_value(array), expected)

    expected, array = self.__get_random_input_and_solution(n)
    with self.subTest(solution=expected, n=n):
      self.assertEqual(get_missing_value(array), expected)

    expected, array = self.__get_random_input_and_solution(n)
    with self.subTest(solution=expected, n=n):
      self.assertEqual(get_missing_value(array), expected)
Exemple #2
0
def solution(array):
    """
    Finds the missing element in a given permutation array [1..(N + 1)].

    Solution with time complexity O(n) and space O(1)
  """

    return get_missing_value(array)
Exemple #3
0
def solution(array):
    """
    Checks if array is a sequence containing each element from 1 to N once, and only once.

    Solution with time complexity O(n) and space O(1)
  """
    n = len(array)
    try:
        return 1 if get_missing_value(array) == n + 1 else 0
    except:
        return 0
 def test_large2(self):
   expected, array = self.__get_random_input_and_solution(100000)
   self.assertEqual(get_missing_value(array), expected)
 def test_simple(self):
   self.assertEqual(get_missing_value([1, 2, 3]), 4)
 def test_double(self):
   self.assertEqual(get_missing_value([2, 1]), 3)
 def test_single(self):
   self.assertEqual(get_missing_value([1]), 2)
 def test_missing_first_or_last(self):
   self.assertEqual(get_missing_value([2, 3, 7, 8, 4, 5, 6, 9, 10]), 1)
   self.assertEqual(get_missing_value([2, 3, 7, 8, 4, 5, 6, 9, 1]), 10)
 def test_empty_and_single(self):
   self.assertEqual(get_missing_value([]), 1)
   self.assertEqual(get_missing_value([2]), 1)
 def test_description_examples(self):
   self.assertEqual(get_missing_value([2, 3, 1, 5]), 4)