*if we get the string like
[“charcoal”,”chimnicoal”,”chestarcoal”]
now how we will find here, becuase here prefix is also matching and suffix is also matching…..
so how can we made the code in javascript,
*
My solution was—>
**if (strs.length === 0) return "";
let output = strs[0];
for (let i = 1; i < strs.length; i++) {
let j = 0;
while (j < output.length && j < strs[i].length && output[j] === strs[i][j]) {
j++;
}
output = output.slice(0, j);
}
return output;**
But it is not working….
New contributor
Sourav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.