Find duplicates within given range k in an array哼利棋牌手机版

Given an array and a positive number k, check whether the array contains any duplicate elements within range k. If k is more than size of the array, the solution should check for duplicates in the complete array.