- 1
Consider an array consisting of the following sequence: 1,2,3,4,5,âŠ..,n. Suppose a number in the sequence is missing.
Write the mathematical process to find the missing number, i.e. some equation. What is the time complexity of finding the missing number in the sequence?
2 Answers
0
Check using for i in array
for
array[i] !== i-1 ;
alert("something is wrong daya" );
+ 2
You will just need to compare the sequence in the array with an equation that matches the specific pattern, the number you store is the one that doesn't match the equation. just make sure when iterating through the array that each number is matched as the rest of the pattern wont be in sync with the equation.
1 1+1
2 2+1
4 3+1 //pattern breaks here.
5 4+1
6 5+1