6 saved 2 bytes
source | link

JavaScript (ES6), 307 307  304 bytes

Saved 2 bytes thanks to @KevinCruijssen

This is embarrassingly long ...

a=>[b=([...a,m=''].map(o=(v,i)=>(i?p==v?!++n:m=o[(o[p]=[o[p]&&o[p]+'|']+(n?i-n+(n>1?'..':'|')+i:i))[m.length]?(x=i-n,j=p):j]:1)&&(p=v,M=n=0)),Object.keys(o).map(k=>(jk=>j-k|!m[6]?o[k]o[k]+'=>'+k:'others')+'=>'+kO,O='others=>'+j).sort()),1/a[1]?[...a]:b,j-a.pop()?b:a.slice(0,x-1)+'+[,others=>'+j]O]].map(a=>M=M[(s=`(${a})`).length]||!M?s:M)&&M

Try it online!Try it online!

JavaScript (ES6), 307 bytes

This is embarrassingly long ...

a=>[b=([...a,m=''].map(o=(v,i)=>(i?p==v?!++n:m=o[(o[p]=[o[p]&&o[p]+'|']+(n?i-n+(n>1?'..':'|')+i:i))[m.length]?(x=i-n,j=p):j]:1)&&(p=v,M=n=0)),Object.keys(o).map(k=>(j-k|!m[6]?o[k]:'others')+'=>'+k).sort()),1/a[1]?[...a]:b,j-a.pop()?b:a.slice(0,x-1)+',others=>'+j].map(a=>M=M[(s=`(${a})`).length]||!M?s:M)&&M

Try it online!

JavaScript (ES6),  307  304 bytes

Saved 2 bytes thanks to @KevinCruijssen

This is embarrassingly long ...

a=>[b=([...a,m=''].map(o=(v,i)=>(i?p==v?!++n:m=o[(o[p]=[o[p]&&o[p]+'|']+(n?i-n+(n>1?'..':'|')+i:i))[m.length]?(x=i-n,j=p):j]:1)&&(p=v,M=n=0)),Object.keys(o).map(k=>j-k|!m[6]?o[k]+'=>'+k:O,O='others=>'+j).sort()),1/a[1]?[...a]:b,j-a.pop()?b:a.slice(0,x-1)+[,O]].map(a=>M=M[(s=`(${a})`).length]||!M?s:M)&&M

Try it online!

5 added the new test cases
source | link

JavaScript (ES6), 307 bytes

This is embarrassingly long ...

a=>[b=([...a,m=''].map(o=(v,i)=>(i?p==v?!++n:m=o[(o[p]=[o[p]&&o[p]+'|']+(n?i-n+(n>1?'..':'|')+i:i))[m.length]?(x=i-n,j=p):j]:1)&&(p=v,M=n=0)),Object.keys(o).map(k=>(j-k|!m[6]?o[k]:'others')+'=>'+k).sort()),1/a[1]?[...a]:b,j-a.pop()?b:a.slice(0,x-1)+',others=>'+j].map(a=>M=M[(s=`(${a})`).length]||!M?s:M)&&M

Try it online!Try it online!

JavaScript (ES6), 307 bytes

This is embarrassingly long ...

a=>[b=([...a,m=''].map(o=(v,i)=>(i?p==v?!++n:m=o[(o[p]=[o[p]&&o[p]+'|']+(n?i-n+(n>1?'..':'|')+i:i))[m.length]?(x=i-n,j=p):j]:1)&&(p=v,M=n=0)),Object.keys(o).map(k=>(j-k|!m[6]?o[k]:'others')+'=>'+k).sort()),1/a[1]?[...a]:b,j-a.pop()?b:a.slice(0,x-1)+',others=>'+j].map(a=>M=M[(s=`(${a})`).length]||!M?s:M)&&M

Try it online!

JavaScript (ES6), 307 bytes

This is embarrassingly long ...

a=>[b=([...a,m=''].map(o=(v,i)=>(i?p==v?!++n:m=o[(o[p]=[o[p]&&o[p]+'|']+(n?i-n+(n>1?'..':'|')+i:i))[m.length]?(x=i-n,j=p):j]:1)&&(p=v,M=n=0)),Object.keys(o).map(k=>(j-k|!m[6]?o[k]:'others')+'=>'+k).sort()),1/a[1]?[...a]:b,j-a.pop()?b:a.slice(0,x-1)+',others=>'+j].map(a=>M=M[(s=`(${a})`).length]||!M?s:M)&&M

Try it online!

4 fixed a comment in the TIO link
source | link

JavaScript (ES6), 307 bytes

This is embarrassingly long ...

a=>[b=([...a,m=''].map(o=(v,i)=>(i?p==v?!++n:m=o[(o[p]=[o[p]&&o[p]+'|']+(n?i-n+(n>1?'..':'|')+i:i))[m.length]?(x=i-n,j=p):j]:1)&&(p=v,M=n=0)),Object.keys(o).map(k=>(j-k|!m[6]?o[k]:'others')+'=>'+k).sort()),1/a[1]?[...a]:b,j-a.pop()?b:a.slice(0,x-1)+',others=>'+j].map(a=>M=M[(s=`(${a})`).length]||!M?s:M)&&M

Try it online!Try it online!

JavaScript (ES6), 307 bytes

This is embarrassingly long ...

a=>[b=([...a,m=''].map(o=(v,i)=>(i?p==v?!++n:m=o[(o[p]=[o[p]&&o[p]+'|']+(n?i-n+(n>1?'..':'|')+i:i))[m.length]?(x=i-n,j=p):j]:1)&&(p=v,M=n=0)),Object.keys(o).map(k=>(j-k|!m[6]?o[k]:'others')+'=>'+k).sort()),1/a[1]?[...a]:b,j-a.pop()?b:a.slice(0,x-1)+',others=>'+j].map(a=>M=M[(s=`(${a})`).length]||!M?s:M)&&M

Try it online!

JavaScript (ES6), 307 bytes

This is embarrassingly long ...

a=>[b=([...a,m=''].map(o=(v,i)=>(i?p==v?!++n:m=o[(o[p]=[o[p]&&o[p]+'|']+(n?i-n+(n>1?'..':'|')+i:i))[m.length]?(x=i-n,j=p):j]:1)&&(p=v,M=n=0)),Object.keys(o).map(k=>(j-k|!m[6]?o[k]:'others')+'=>'+k).sort()),1/a[1]?[...a]:b,j-a.pop()?b:a.slice(0,x-1)+',others=>'+j].map(a=>M=M[(s=`(${a})`).length]||!M?s:M)&&M

Try it online!

    Post Undeleted by Arnauld
3 fixed version
source | link
    Post Deleted by Arnauld
2 saved 13 bytes
source | link
1
source | link