Number of ways to insert two pairs of parentheses into a string of N characters | Java implementation of the approach ; Function to return the number of ways to insert the bracket pairs ; Driver code
import java . util . * ; class GFG { static int cntWays ( String str , int n ) { int x = n + 1 ; int ways = x * x * ( x * x - 1 ) / 12 ; return ways ; } public static void main ( String [ ] args ) { String str = " ab " ; int n = str . length ( ) ; System . out . println ( cntWays ( str , n ) ) ; } }