Grokking 75: Top Coding Interview Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Solution: Contains Duplicate II
On this page

Problem Statement

Given an array of integers nums and an integer k, return true if there are any two different indices i and j in the array where nums[i] == nums[j] and abs(i - j) <= k. Otherwise, return false.

Examples

Example 1:

  • Input: nums = [10, 20, 10, 30], k = 1
  • Output: false
  • Explanation: The number 10 appears at positions 0 and 2. The difference between these positions is 2, which is not less than k.

Example 2:

  • Input: nums = [5, 15, 25, 5, 35], k = 3
  • Output: true
  • Explanation: The number `5

.....

.....

.....

Like the course? Get enrolled and start learning!

On this page