DEV Community

utmfcim
utmfcim

Posted on

Find sublists in list by sum

Help me please with task.

Given a list L = (A0, A1 , A2, ..., An). Find sublists if they exist L1 = (Ai, Ai + 1, ..., Ai + k), i + k <= N, i >= 1, for which M = Ai + Ai + 1 + ... Ai + k.

For example:

L = (1 3 -16 5 7 8 2 2), M=12
Result:

L1 = (1 3 -16) //1+3-16=12
L1 = (5 7) //5+7=12
L1 = (8 2 2) //8+2+2=12

Top comments (0)