Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Statistics For Business Decision Making And Analysis

Authors: Robert Stine, Dean Foster

2nd Edition

978-0321836519, 321836510, 978-0321890269

More Books

Students also viewed these Programming questions

Question

What is the purpose of a Notice of Assessment?

Answered: 1 week ago

Question

discuss why people do or do not exercise,

Answered: 1 week ago

Question

describe how to recognize disordered eating,

Answered: 1 week ago