Problem Solving with Arman (ML+Algo)
Ссылка
нажмите — покажем
нажмите — покажем
#4032 | Longest Subarray With at Most K Distinct Prime Factors
Topics: prime factorization, 2 pointers
Problem Statement:
You are given an integer array numsconsisting of positive integers and an integer k. The prime factor set of a subarray is the union of the distinct prime factors of all its elements. Return the length of the longest subarray whose prime factor set contains at most k distinct prime factors. If no such subarray exists, return 0.
Input: nums = [7,6,10,12,11], k = 3
Output: 3
Explanation: longest subarray -> [6, 10, 12]
* 6: {2, 3}
* 10: {2, 5}
* 12: {2, 3}
Union set of prime factors: {2, 3, 5} and number of sets is at most K.
🔗 Link: https://leetcode.com/problems/longest-subarray-with-at-most-k-distinct-prime-factors/
#POTD #LeetCode
1 · 56 ·