Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I solved my problem by using simple nested loops and comparisons but I'm wondering if there is a well known Selection Algorithm to solve my problem.

Let's say I have an array such as

[1, 10, 250, 9, 8,8, 249, 249, 248, 247, 2, 4, 9, 10, 9, 7, 6]

I need to find subarrays

[6,7,8,9,10] [8,9,10] [247, 248, 249, 250]

Subarrays should be min. 3 length size.

I dont want a solution but a similar algorithm would help me refactor my code.

I'm currently doing this with nested loops and using buffer collections.

share|improve this question
    
If the original array contained an 11, how should the subarrays be listed? –  MichaelT Apr 2 at 19:23
    
[6,7,8,9,10,11] [8,9,10] [247, 248, 249, 250] –  Kubi Apr 2 at 19:31
    
there is no order in subarrays. All items can only be used one time in subarrays –  Kubi Apr 2 at 19:41
    
The necessary determination was if [6,7,8,9,10,11] [8,9,10] was the only answer or if [6,7,8,9,10] [8,9,10,11] is a valid answer. –  MichaelT Apr 2 at 19:46
    
they are both valid answers as long as 11 is used once –  Kubi Apr 2 at 20:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.