c# - Minimum groups of contiguous sequences -


i have following problem best described in diagram: consider following sequences (can type of sequence: numbers, dates (in case dates), etc.)

diagram

i find groups of longest contiguous sequence output in latter example, i.e. minimum amount of groups containing longest sequence possible.

i thought of going sort of sorting/ordering (min/max doesn't seem of here have empty gaps), first left point right, i'm not sure either.

just spit-balling pseudo-code last time coded this:

var outputranges = new list<range>(); foreach (var range in inputranges) {    // let range.touches(range) define function returns true    // iff 2 ranges overlap @ (that is, a.start and/or a.end    // between b.start , b.end)    var overlaps = outputranges.where(range.touches).tolist();     // if there no overlaps, add output    if (!overlaps.any())    {        outputranges.add(range);    }    // if there overlaps, merge them    else    {        outputranges.removeall(overlaps);        overlaps.add(range);        outputrange.add(new range() {            start = overlaps.min(_=>_.start),            end = overlaps.max(_=>_.end)        });    } } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -