Maximum Subsequence Score | Biweekly Contest 96 | Leetcode

preview_player
Показать описание


************************************************

**************************************************

Please show support and subscribe if you find the content useful.
Рекомендации по теме
Комментарии
Автор

Thank you so much ! This is very helpful for dumb person like me.

jiaweiwu
Автор

hi mohan great explaination as always one thing to add if we are at ith minimum element we must have to take ith element from nums1 for addition we just cant take any k maximum elements till i your solution is working because we are going from maximum to minimum element so we will never get the answer greater than any of our previous result

AnandKumar-kzls
Автор

For the follow up qsn
We can get the sum of each k length subarrays by using sliding window & now remaining part is to get min element in each k length subarray

We can use set or priority queue to get the min element across k length subarrays

finally merging above two steps through sliding window of length k we can do simulation

krishankant
Автор

Seriously Great explanation 💯💯. Keep up the good work man. Love that you just don't give the answer right away, you start from brute force and make us think how we can optimize this.

sandipanmahata
Автор

Idea of fixing minimum element was awesome, I tried and used heap but was not able to think of fixing the minimum 😭.

josephaj
Автор

enjoyed solving this qsn pretty interesting one

krishankant
Автор

``` class Solution {
public:
long long mx=0;
void dfs(int index, vector<int>& nums1, vector<int>& nums2, int k, int sum, int mini, int n)
{
if(k==0)
{
int temp=sum*mini;
if(temp>mx)mx=temp;
return;
}
if(index>=n)return;
// int res=0;

dfs(index+1, nums1, nums2, k, sum, mini, n);

dfs(index+1, nums1, nums2, k-1, sum+nums1[index], min({mini, nums2[index]}), n);

}
long long maxScore(vector<int>& nums1, vector<int>& nums2, int k) {

int n=nums1.size();
dfs(0, nums1, nums2, k, 0, INT_MAX, n);
return mx;
}
};```

Is this recursive solution right?

codingwithanonymous
Автор

Thank you sir, you are one of the best programmers on the feild, so much clarity and pure brilliance;

psurya
join shbcf.ru