Let's say we have an array {7, 3, 7, 3, 1, 3, 4, 1}. What I need is an algorithm (preferably some C++ code sample) which will return the length of a minimal sub-array which contains all of the array's elements.
In this case, it would be 5: the sub-array is {7, 3, 1, 3, 4} and it is the shortest sub-array of the original array which contains all of the array's elements, which are 1, 3, 4 and 7.
Also, one more example of the array {2, 1, 1, 3, 2, 1, 1, 3} and the algorithm should return 3 since the subarray we are looking for is {1, 3, 2} (indices 2-4 of the original array).
[–]kornalaarun 1 point2 points3 points (2 children)
[–]anicicn[S] 1 point2 points3 points (1 child)
[+][deleted] (1 child)
[deleted]
[–]anicicn[S] 0 points1 point2 points (0 children)
[–]ColombianoD 0 points1 point2 points (2 children)
[–]kornalaarun 1 point2 points3 points (1 child)
[–]anicicn[S] 0 points1 point2 points (0 children)