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.