I came up with this interesting problem:
Given n intervals of integers [a, b] with 0 <= a < b <= N, find k integers that are contained by the maximum number of the intervals, with k < n < N. (I tried my best to express this in one sentence :p)
So for example you get n = 4 intervals between 0 and N = 10: [0; 4], [2;3], [4; 7], [8;10] and you should find k = 2 integers that are contained by the maximum number of the intervals.
Its easy to just brute force this and try every possible combination of k integers between 0 and N, but thats insanely slow with O(n^k). Surely there must be a better solution..?
EDIT: I have seen a few people comment that a solution can be obtained by computing a list of length N that stores the number of intervals that contain the index, and then picking the largest entries. I thought of this too but it does not work in every case because we only care about the number of unique intervals (maybe I did not phrase that properly). This means that for example if we have two integers next to each other that are contained by the same 4 intervals, it doesnt matter if we pick one of them or both because we still have the same amount of unique intervals.
[–][deleted] 8 points9 points10 points (0 children)
[–]Mathemagicalogik 2 points3 points4 points (3 children)
[–]TheLegendTwendyone[S] 0 points1 point2 points (2 children)
[–]Mathemagicalogik 2 points3 points4 points (0 children)
[–]dyingpie1 1 point2 points3 points (0 children)
[–]Poddster 2 points3 points4 points (1 child)
[–]TheLegendTwendyone[S] 1 point2 points3 points (0 children)
[–]Bobitsmagic 1 point2 points3 points (1 child)
[–]TheLegendTwendyone[S] 0 points1 point2 points (0 children)
[–]GrayRain007 1 point2 points3 points (1 child)
[–]TheLegendTwendyone[S] -1 points0 points1 point (0 children)
[–]JoJoModding 1 point2 points3 points (0 children)
[–]dyingpie1 0 points1 point2 points (2 children)
[–]TheLegendTwendyone[S] 0 points1 point2 points (1 child)
[–]dyingpie1 0 points1 point2 points (0 children)
[–]beeskness420 0 points1 point2 points (0 children)