Leetcode 2099 | Find Subsequence Of Length K With The Largest Sum | Leetcode POTD

preview_player
Показать описание
Leetcode 2099 | Find Subsequence Of Length K With The Largest Sum | Leetcode POTD

Description

Hello Everyone today i am here to solve problem number 2099 on LeetCode which is about to find the maximum sum of subsequence for the k length, i have completed it in C++ i hope you will like the video and we will go through each step one by one !!

Launching Something Good Soon....

#Leetcode #DSA #leetcodesolution #CPP #Coding #Programming #leetcodedaily #computerscience

keywords

Find Subsequence Of Length K With The Largest Sum, leetcode cpp, leetcode c++, leetcode dsa, leetcode potd, leetcode, leetcode solution, leetcode easy, leetcode daily, Leetcode 2099, data structures and algorithms, data structures, subsequence problem, leetcode challenge, largest sum, cpp coding, leetcode tips, find subsequence, software engineering, python, leetcode solutions, dynamic programming, competitive programming, backtracking, coding interview, algorithm challenge
Рекомендации по теме
Комментарии
Автор

Solved in few lines but not optimize approach

var maxSubsequence = function(nums, k) {
const indexed = nums.map((num, idx) => [num, idx]);
indexed.sort((a, b) => b[0] - a[0])
const topK = indexed.slice(0, k)
topK.sort((a, b) => a[1] - b[1])

return topK.map(pair => pair[0])
};

ujjwaltyagi
visit shbcf.ru