2023 Jan MS OA:1) Find the wrong code and 2) OCR if two strings are equal
137

Repos:I had to find bugs in the following code.
The algorithm takes in input a vector of integer sorted in a non-decreasing order and an integer K. The algorithm returns true if the vector contains only and all the numbers between 1 and k at least once, and false otherwise:

([1,1,2,3,3,4],4) --> true

([1,1,3],3) --> false

This was the implementation:

bool algorithm(vector &A, int k)
{
n = A.size();
for(int 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;
}
}

and 2) OCR text can sometime cannot read character from source, so it will be replaced with question mark "?"
for example, apple can be translated as a??le by OCR because two p characters are unreadable.
for example, aaaaaaaaaaaaa can be ?????????????
but to save space it is interpret as a13

given two ocr texts, compare if they COULD be equal
a2le and app?e are equal

Comments (3)