<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2,3,1], k = 3
<strong>Output:</strong> true
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,0,1,1], k = 1
<strong>Output:</strong> true
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2,3,1,2,3], k = 2
<strong>Output:</strong> false
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
	<li><code>0 &lt;= k &lt;= 10<sup>5</sup></code></li>
</ul>

class Solution:
    def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:
        frequency_dict = {}

        if len(nums) <= 1:
            return False
        if len(set(nums)) == len(nums):
            return False
        if k == 0:
            return False


        for i, num in enumerate(nums):
            if num not in frequency_dict.keys():
                frequency_dict[num] = []
                frequency_dict[num].append(i)
            else:
                frequency_dict[num].append(i)

        # # multiple_indices = [k,v for k,v in frequency_dict.items() if len(v) >= 2]
        multiple_indices = [k for k,v in frequency_dict.items() if len(v) >1 ]
        for key in multiple_indices:
            value = frequency_dict[key]
            for i in range(1,len(value)):
                
                if i == 1:
                    leap_size = value[i] - value[i-1]
                    min_leap = leap_size
                    print(min_leap)
                elif i > 1:    
                    leap_size = value[i] - value[i-1]
                    if leap_size < min_leap:
                        min_leap = leap_size
            print(min_leap)
        if abs(min_leap) <= k:
            return True
        else:
            return False


31138