DEV Community

utmfcim
utmfcim

Posted on

2

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay