I have a typical pattern searching problem where I need to identify where multiple patterns are appearing within an array and single them out.
ex: ['horse', 'camel', 'horse', 'camel', 'tiger', 'horse', 'camel', 'horse', 'camel']
function should return
['horse', 'camel'],
['horse', 'camel', 'horse'],
['camel', 'horse', 'camel'],
['horse', 'camel', 'horse', 'camel']
i.e. finding patterns that are repeating within an array which can become a sub-array,
Or the other way of defining is -> Find all the sub-arrays which are occurring more than 1 times in main array.
i.e. resulting arrays should have length > 1
->
[1, 2, 3, 1, 2, 1, 4, 5]
=> [1,2,3]
and [1,4,5]
both are sub-arrays but [1,2,3]
is recurring/repeating sub-array NOT [1,4,5]
Looking for a suitable efficient algorithm instead of brute-force looping solutions.