This function given a non empty array A of N intergers(sorted in non decreasing order) and integer
Fantastic news! We've Found the answer you've been seeking!
Question:
This function given a non empty array A of N intergers(sorted in non decreasing order) and integer K, checks whether A contains numbers 1,2...K (every number from 1 to K at least once)and no other number
function solution(A, K) {
var n = A.length;
for (var i = 0; i < n - 1; i++) {
if (A[i] + 1 < A[i + 1])
return false;
}
if (A[0] != 1 && A[n - 1] != K)
return false;
else
return true;
}
Related Book For
Statistics For Business Decision Making And Analysis
ISBN: 9780321890269
2nd Edition
Authors: Robert Stine, Dean Foster
Posted Date: