Learner Level
Implement the findMissingNumberFromOneToN method that finds the missing value from a sequence that should contain numbers from 1 to n.
The input contains an integer array nums, its length size, and a number n. The array contains numbers from 1 to n with exactly one number missing.
Your task is to find and return the missing number. For example, if nums = [1,2,4,5] and n = 5, the missing number is 3.
The sum of numbers from 1 to n is known using the formula n * (n + 1) / 2.
Calculate the expected sum, subtract the actual sum of the array, and the remaining value is the missing number.
Pseudocode:
function findMissingNumberFromOneToN(nums, size, n):
expectedSum = n * (n + 1) / 2
actualSum = 0
for each value in nums:
actualSum = actualSum + value
return expectedSum - actualSum