leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 43527ce1012dffda965e2cacd045df4a0151845d
parent 24989a7783f4dbb66291d0cd0326a971eb989e16
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri,  5 Jul 2024 18:18:09 +0200

1 Random Problem

Diffstat:
AProblems/1673.cpp | 15+++++++++++++++
MREADME.md | 1+
2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/Problems/1673.cpp b/Problems/1673.cpp @@ -0,0 +1,15 @@ +class Solution { + public: + vector<int> mostCompetitive(const vector<int> &nums, int k) const { + vector<int> st; + st.reserve(k); + + for (int i = 0; i < size(nums); i++) { + while (!st.empty() && k - size(st) < size(nums) - i && st.back() > nums[i]) + st.pop_back(); + if (size(st) < k) st.push_back(nums[i]); + } + + return st; + } +}; diff --git a/README.md b/README.md @@ -922,6 +922,7 @@ for solving problems. | 1669 | Medium | [Merge In Between Linked Lists](Problems/1669.cpp) | | 1670 | Medium | [Design Front Middle Back Queue](Problems/1670.cpp) | | 1672 | Easy | [Richest Customer Wealth](Problems/1672.cpp) | +| 1673 | Medium | [Find the Most Competitive Subsequence](Problems/1673.cpp) | | 1675 | Hard | [Minimize Deviation in Array](Problems/1675.cpp) | | 1679 | Medium | [Max Number of K-Sum Pairs](Problems/1679.cpp) | | 1680 | Medium | [Concatenation of Consecutive Binary Numbers](Problems/1680.cpp) |