text: Number of ways to insert two pairs of parentheses into a string of N characters | C ++ implementation of the approach ; Function to return the number of ways to insert the bracket pairs ; Driver code
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; int cntWays ( string str , int n ) { int x = n + 1 ; int ways = x * x * ( x * x - 1 ) / 12 ; return ways ; } int main ( ) { string str = " ab " ; int n = str . length ( ) ; cout << cntWays ( str , n ) ; return 0 ; }