commit 0915a63bbe73399437f5c15262a4a1847378ade8 parent 5f4b0531828ed02edd6c1d8a1e3f5141fad84126 Author: Dimitrije Dobrota <mail@dimitrijedobrota.com> Date: Thu, 11 Jul 2024 14:06:05 +0200 1 Random Problem Diffstat:
A | Problems/3159.cpp | | | 18 | ++++++++++++++++++ |
M | README.md | | | 1 | + |
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/Problems/3159.cpp b/Problems/3159.cpp @@ -0,0 +1,18 @@ +class Solution { + public: + vector<int> occurrencesOfElement(vector<int> &nums, vector<int> &queries, int x) { + static int count[100001]; + int sz = 1; + + for (int i = 0; i < size(nums); i++) { + if (nums[i] != x) continue; + count[sz++] = i; + } + + for (auto &query : queries) { + query = query < sz ? count[query] : -1; + } + + return queries; + } +}; diff --git a/README.md b/README.md @@ -1282,5 +1282,6 @@ for solving problems. | 3106 | Medium | [Lexicographically Smallest String After Operations With Constraint](Problems/3106.cpp) | | 3110 | Easy | [Score of a String](Problems/3110.cpp) | | 3111 | Medium | [Minimum Rectangles to Cover Points](Problems/3111.cpp) | +| 3159 | Medium | [Find Occurrences of an Element in an Array](Problems/3159.cpp) | | 3195 | Medium | [Find the Minimum Area to Cover All Ones I](Problems/3195.cpp) | | 3211 | Medium | [Generate Binary Strings Without Adjacent Zeros](Problems/3211.cpp) |