Question: This function, given a non - empty array A of N integers ( sorted in non - decreasing order ) and integer K , checks
This function, given a nonempty array A of N integers sorted in nondecreasing order and integer K checks whether A contains numbers K every number from to K at least once and no other numbers.
For example, given the following array A and K :
A
A
A
A
A
The function should return true.
For the following array A and K :
A
A
A
The function should return false.
The attached code is still incorrect for some inputs. Despite the errors the code may produce a correct answer for the example test cases. The goal of the exercise is to find and fix the bugs in the implementation. You can modify at most two lines.
Assume that:
N and K are integers within the range ;
each element of array A is an integer within the range ;
array A is sorted in nondecreasing order.
Here is the code:
class Solution
public boolean solutionint A int K
int n Alength;
for int i ; i n ; i
if Ai Ai
return false;
if A && An K
return false;
else
return true;
I am not able to perfom this by changing lines of code. Please help in this, and make sure it works for all cases and edge cases. NOTE again: Only need to change lines of code to make it work.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
