Count N | Java program for the above approach ; Function to count N - length strings consisting of vowels only sorted lexicographically ; Initializing vector to store count of strings . ; Summing up the total number of combinations . ; Return the result ; Function Call
import java . util . * ; public class Main { static int findNumberOfStrings ( int N ) { Vector < Integer > counts = new Vector < Integer > ( ) ; for ( int i = 0 ; i < 5 ; i ++ ) { counts . add ( 1 ) ; } for ( int i = 2 ; i <= N ; i ++ ) { for ( int j = 3 ; j >= 0 ; j -- ) counts . set ( j , counts . get ( j ) + counts . get ( j + 1 ) ) ; } int ans = 0 ; for ( Integer c : counts ) ans += c ; return ans ; } public static void main ( String [ ] args ) { int N = 2 ; System . out . print ( findNumberOfStrings ( N ) ) ; } }