Given a string S of length N consisting of "+" and "-". here, A sequence of first n + 1 integers is called a Plus Minus
Posted: Fri Jul 08, 2022 6:35 am
c
c++
python
Given a string S of length N consisting of "+" and "-". here, A sequence of first n + 1 integers is called a Plus Minus Sequence, if for all valid i's. If s == '-', perm id greater than perm [i+1] wher eas If s =='+', perm is smaller than perm[i+1]. Return the number of valid Plus Minus Sequences. The answer can b e large, so return answer with 109 + 7 modulo. Constraints: 1≤n≤ 104 Input Format The first and only line will contain a single string S of length N co ntaining only '+' and '-' as characters. Output Format Print a single integer denoting the number of valid Plus Minus Seque nces.
Sample Testcase #0 Testcase Input Testcase Output 5 Explanation The 5 valid permutations of (0, 1, 2, 3) which are Plus Minus Sequen ces are: (1, 0, 3, 2) (2, 0, 3, 1) (2, 1, 3, 0) (3, 0, 2, 1) (3, 1, 2, 0)
Sample Testcase #1 Testcase Input Testcase Output 1 Explanation The 1 and only valid permutations of (0, 1) which is a Plus Minus Seq uence is (1,0).
import java.io.*; import java.util.*; import java.text.*; import java.math.*: import java.util.regex.*; public class Solution { } public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output t }
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { } /* Enter your code here. Read input from STDIN. Print out return 0; I
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; C- int main() { I /* Enter your code here. Read input from STDIN. Print out return 0; }