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

0% completed

Solution: Contains Duplicate II
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

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!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible