Saturday, 4 Dec 2021
Category: prefix-sum

#include using namespace std;  int totalValidArrays(int a[], int b[],                     int N){        int dp[N + 1][b[N – 1] + 1];          int pref[N + 1][b[N – 1] + 1];          memset(dp, 0, sizeof(dp)),        memset(pref, 0, sizeof(pref));          dp[0][0] = 1;          for (int i = 0; i

Given an array, arr[] and a positive integer K. The task is to find the position say i of the element in arr[] such that prefix sum till i-1, i and suffix sum till i+1 are in Geometric Progression with common ratio K. Examples:Input: arr[] = { 5, 1, 4, 20, 6, 15, 9, 10 }, […]

#include using namespace std;void find_prefixsum(int M, int N, vector& arr,                    vector& dp){        for (int i = 0; i

Given an array arr[] consisting of N positive integers, the task is to find the prefix factorials of a prefix sum array of the given array i.e.,  .Examples:Input: arr[] = {1, 2, 3, 4}Output: 1 6 720 3628800Explanation:The prefix sum of the given array is {1, 3, 6, 10}. Therefore, prefix factorials of the obtained […]

Longest Non-Increasing Subsequence in a Binary StringGiven a binary string S of size N, the task is to find the length of the longest non-increasing subsequence in the given string S.Examples:Input: S = “0101110110100001011”Output: 12 Explanation: The longest non-increasing subsequence is “111111100000”, having length equal to 12.Input: S = 10101Output: 3Approach: The given problem can be […]