Pergunta de entrevista da empresa Air France

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.

Respostas da entrevista

Sigiloso

18 de mar. de 2024

Using JS

Sigiloso

23 de nov. de 2024

def find_missing_number(arr): n = len(arr) # n is the number of elements in the array expected_sum = n * (n + 1) // 2 # Sum of first n natural numbers actual_sum = sum(arr) # Sum of the elements in the array missing_number = expected_sum - actual_sum # The missing number return missing_number # Example usage: arr = [0, 1, 2, 4] # Here, n = 4, and the missing number is 3 missing = find_missing_number(arr) print(f"The missing number is: {missing}")