Tap here to switch tabs
Problem
Submissions

Problem: Longest Subsequence With Limited Sum

Longest Subsequence With Limited Sum asks you to find, for each query, the maximum number of elements that can form a subsequence of an integer array whose total does not exceed that query, then return all counts.

Statement

You are given an integer array, nums, of length n, and an integer array, queries, of length m.

For each element in queries, determine the maximum number of elements that can be selected from nums to form a subsequenceA subsequence is formed by removing zero or more elements from the array without changing the order of the remaining elements. such that the sum of the selected elements is less than or equal to the query value.

Return an array answer of length m, where answer[i] represents the size of the largest subsequence of nums whose sum is less than or equal to queries[i].

Constraints

  • n ==== nums.length

  • m ==== queries.length

  • 1≤1 \leq n, m ≤103\leq 10^3

  • 1≤1 \leq nums[i], queries[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Longest Subsequence With Limited Sum

Longest Subsequence With Limited Sum asks you to find, for each query, the maximum number of elements that can form a subsequence of an integer array whose total does not exceed that query, then return all counts.

Statement

You are given an integer array, nums, of length n, and an integer array, queries, of length m.

For each element in queries, determine the maximum number of elements that can be selected from nums to form a subsequenceA subsequence is formed by removing zero or more elements from the array without changing the order of the remaining elements. such that the sum of the selected elements is less than or equal to the query value.

Return an array answer of length m, where answer[i] represents the size of the largest subsequence of nums whose sum is less than or equal to queries[i].

Constraints

  • n ==== nums.length

  • m ==== queries.length

  • 1≤1 \leq n, m ≤103\leq 10^3

  • 1≤1 \leq nums[i], queries[i] ≤105\leq 10^5