Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int countMatchingSubarrays(vector<int>& nums, vector<int>& pattern) {
- int m = pattern.size() + 1; // Length of subarray we need to check
- int n = nums.size(); // Size of nums array
- int ans = 0; // Variable to store the count of matching subarrays
- for (int i = 0; i <= n - m; i++) {
- vector<int> aux;
- for (int j = i; j < i + m; j++) {
- aux.push_back(nums[j]);
- }
- int j;
- for (j = 0; j < m - 1; j++) {
- if (pattern[j] == 1 && aux[j + 1] <= aux[j]) {
- break;
- } else if (pattern[j] == 0 && aux[j + 1] != aux[j]) {
- break;
- } else if (pattern[j] == -1 && aux[j + 1] >= aux[j]) {
- break;
- }
- }
- if (j == m - 1) {
- ans++;
- }
- }
- return ans; // Return the count of matching subarrays
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement