Bug Report for https://neetcode.io/problems/longest-common-prefix
class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
string last = strs[0];
int checkSize = last.size();
for(const auto& str : strs)
for(int i = 0; i<checkSize; i++)
if(str[i] != last[i])
checkSize = i;
return last.substr(0,checkSize);
}
};
This code shouldn't pass submission, it has a bug.
Suppose testcase : ["flower", "fl"] -> here checkSize is larger than str[i] for i =1.
But this code is getting accepted.