BackeasyHashing Swiggy

Medieval Kingdom Package Tracker Solution

Problem Statement

Given an array of packages and a window size, return true if any package is a duplicate within the window, otherwise return false.

Example 1
Input
[101, 4, 5, 101, 4, 5]
Output
true

Explanation: Step-by-step: with input [101, 4, 5, 101, 4, 5], we create a sliding window of size 3. We check if any package is a duplicate within the window. In this case, the package 101 is a duplicate within the window [101, 4, 5]. Therefore, the output is true.

Example 2
Input
[1, 2, 3, 4, 5]
Output
false

Explanation: Step-by-step: with input [1, 2, 3, 4, 5], we create a sliding window of size 3. We check if any package is a duplicate within the window. In this case, all elements are unique within the window. Therefore, the output is false.

Constraints

  • 1 <= n <= 10^5
  • 0 <= k <= 10^5
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free