Tap here to switch tabs
Problem
Submissions

Problem: Longest Subarray With at Most K Distinct Prime Factors

med
30 min
Try to solve the Longest Subarray With at Most K Distinct Prime Factors problem.

Statement

You are given an integer array nums and an integer k.

A subarray is valid if the total number of distinct prime factors across all elements in the subarray is at most k.

Return the maximum length of a valid contiguous subarray.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 2≤2 \leq nums[i] ≤105\leq 10^5

  • 1≤1 \leq k ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Longest Subarray With at Most K Distinct Prime Factors

med
30 min
Try to solve the Longest Subarray With at Most K Distinct Prime Factors problem.

Statement

You are given an integer array nums and an integer k.

A subarray is valid if the total number of distinct prime factors across all elements in the subarray is at most k.

Return the maximum length of a valid contiguous subarray.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 2≤2 \leq nums[i] ≤105\leq 10^5

  • 1≤1 \leq k ≤104\leq 10^4