let str = 'kabc5 sabc0 abjcde abcfg fgabcfg2 safds abc'
let arr = str.split(/\s+/)
let res = 1
const find = arr => {
let temp = {}
arr.forEach(v => {
let key = v.substr(0, res)
temp[key] = (temp[key] >>> 0) + 1
})
arr = arr.filter(v => temp[v.substr(0, res)] > 1)
if (arr.length) {
res += 1
find(arr)
}
}
find(arr)
console.log(res)
мой вариант решения