codeparrot/xlcost-text-to-code huggingface dataset:
Find postorder traversal of BST from preorder traversal | Java program for finding postorder traversal of BST from preorder traversal ; Function to find postorder traversal from preorder traversal . ; If entire preorder array is traversed then return as no more element is left to be added to post order array . ; If array element does not lie in range specified , then it is not part of current subtree . ; Store current value , to be printed later , after printing left and right subtrees . Increment preIndex to find left and right subtrees , and pass this updated value to recursive calls . ; All elements with value between minval and val lie in left subtree . ; All elements with value between val and maxval lie in right subtree . ; Function to find postorder traversal . ; To store index of element to be traversed next in preorder array . This is passed by reference to utility function . ; Driver code ; Calling function
import java . util . * ; class Solution { static class INT { int data ; INT ( int d ) { data = d ; } } static void findPostOrderUtil ( int pre [ ] , int n , int minval , int maxval , INT preIndex ) { if ( preIndex . data == n ) return ; if ( pre [ preIndex . data ] < minval pre [ preIndex . data ] > maxval ) { return ; } int val = pre [ preIndex . data ] ; preIndex . data ++ ; findPostOrderUtil ( pre , n , minval , val , preIndex ) ; findPostOrderUtil ( pre , n , val , maxval , preIndex ) ; System . out . print ( val + " ▁ " ) ; } static void findPostOrder ( int pre [ ] , int n ) { INT preIndex = new INT ( 0 ) ; findPostOrderUtil ( pre , n , Integer . MIN_VALUE , Integer . MAX_VALUE , preIndex ) ; } public static void main ( String args [ ] ) { int pre [ ] = { 40 , 30 , 35 , 80 , 100 } ; int n = pre . length ; findPostOrder ( pre , n ) ; } }
Height of binary tree considering even level leaves only | Java Program to find height of the tree considering only even level leaves . ; A binary tree node has data , pointer to left child and a pointer to right child ; Base Case ; left stores the result of left subtree , and right stores the result of right subtree ; If both left and right returns 0 , it means there is no valid path till leaf node ; Helper function that allocates a new node with the given data and NULL left and right pointers . ; Driver program to test above functions ; Let us create binary tree shown in above diagram
class GfG { static class Node { int data ; Node left ; Node right ; } static int heightOfTreeUtil ( Node root , boolean isEven ) { if ( root == null ) return 0 ; if ( root . left == null && root . right == null ) { if ( isEven == true ) return 1 ; else return 0 ; } int left = heightOfTreeUtil ( root . left , ! isEven ) ; int right = heightOfTreeUtil ( root . right , ! isEven ) ; if ( left == 0 && right == 0 ) return 0 ; return ( 1 + Math . max ( left , right ) ) ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return ( node ) ; } static int heightOfTree ( Node root ) { return heightOfTreeUtil ( root , false ) ; } public static void main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . left . right . left = newNode ( 6 ) ; System . out . println ( " Height ▁ of ▁ tree ▁ is ▁ " + heightOfTree ( root ) ) ; } }
Find Height of Binary Tree represented by Parent array | Java program to find height using parent array ; This function fills depth of i 'th element in parent[]. The depth is  filled in depth[i]. ; If depth [ i ] is already filled ; If node at index i is root ; If depth of parent is not evaluated before , then evaluate depth of parent first ; Depth of this node is depth of parent plus 1 ; This function returns height of binary tree represented by parent array ; Create an array to store depth of all nodes / and initialize depth of every node as 0 ( an invalid value ) . Depth of root is 1 ; fill depth of all nodes ; The height of binary tree is maximum of all depths . Find the maximum value in depth [ ] and assign it to ht . ; Driver program to test above functions ; int parent [ ] = { 1 , 5 , 5 , 2 , 2 , - 1 , 3 } ;
class BinaryTree { void fillDepth ( int parent [ ] , int i , int depth [ ] ) { if ( depth [ i ] != 0 ) { return ; } if ( parent [ i ] == - 1 ) { depth [ i ] = 1 ; return ; } if ( depth [ parent [ i ] ] == 0 ) { fillDepth ( parent , parent [ i ] , depth ) ; } depth [ i ] = depth [ parent [ i ] ] + 1 ; } int findHeight ( int parent [ ] , int n ) { int depth [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { depth [ i ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { fillDepth ( parent , i , depth ) ; } int ht = depth [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( ht < depth [ i ] ) { ht = depth [ i ] ; } } return ht ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; int parent [ ] = new int [ ] { - 1 , 0 , 0 , 1 , 1 , 3 , 5 } ; int n = parent . length ; System . out . println ( " Height ▁ is ▁ " + tree . findHeight ( parent , n ) ) ; } }
How to determine if a binary tree is height | A binary tree node has data , pointer to left child , and a pointer to right child ; Returns true if binary tree with root as root is height - balanced ; for height of left subtree ; for height of right subtree ; If tree is empty then return true ; Get the height of left and right sub trees ; If we reach here then tree is not height - balanced ; The function Compute the " height " of a tree . Height is the number of nodes along the longest path from the root node down to the farthest leaf node . ; base case tree is empty ; If tree is not empty then height = 1 + max of left height and right heights ; Driver code
class Node { int data ; Node left , right ; Node ( int d ) { data = d ; left = right = null ; } } class BinaryTree { Node root ; boolean isBalanced ( Node node ) { int lh ; int rh ; if ( node == null ) return true ; lh = height ( node . left ) ; rh = height ( node . right ) ; if ( Math . abs ( lh - rh ) <= 1 && isBalanced ( node . left ) && isBalanced ( node . right ) ) return true ; return false ; } int height ( Node node ) { if ( node == null ) return 0 ; return 1 + Math . max ( height ( node . left ) , height ( node . right ) ) ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . left . left . left = new Node ( 8 ) ; if ( tree . isBalanced ( tree . root ) ) System . out . println ( " Tree ▁ is ▁ balanced " ) ; else System . out . println ( " Tree ▁ is ▁ not ▁ balanced " ) ; } }
Find height of a special binary tree whose leaf nodes are connected | Java implementation to calculate height of a special tree whose leaf nodes forms a circular doubly linked list ; User defined node class ; Constructor to create a new tree node ; function to check if given node is a leaf node or node ; If given node ' s ▁ left ' s right is pointing to given node and its right ' s ▁ left ▁ is ▁ pointing ▁ to ▁ the ▁ node ▁ ▁ itself ▁ then ▁ it ' s a leaf ; Compute the height of a tree -- the number of Nodes along the longest path from the root node down to the farthest leaf node . ; if node is NULL , return 0 ; if node is a leaf node , return 1 ; compute the depth of each subtree and take maximum ; Driver code ; Given tree contains 3 leaf nodes ; create circular doubly linked list out of leaf nodes of the tree set next pointer of linked list ; set prev pointer of linked list ; calculate height of the tree
import java . io . * ; import java . util . * ; class Node { int data ; Node left , right ; Node ( int key ) { data = key ; left = right = null ; } } class GFG { static boolean isLeaf ( Node node ) { return ( node . left != null && node . left . right == node && node . right != null && node . right . left == node ) ; } static int maxDepth ( Node node ) { if ( node == null ) return 0 ; if ( isLeaf ( node ) ) return 1 ; return 1 + Math . max ( maxDepth ( node . left ) , maxDepth ( node . right ) ) ; } public static void main ( String args [ ] ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . left . left . left = new Node ( 6 ) ; Node L1 = root . left . left . left ; Node L2 = root . left . right ; Node L3 = root . right ; L1 . right = L2 ; L2 . right = L3 ; L3 . right = L1 ; L3 . left = L2 ; L2 . left = L1 ; L1 . left = L3 ; System . out . println ( " Height ▁ of ▁ tree ▁ is ▁ " + maxDepth ( root ) ) ; } }
Diameter of a Binary Tree | Class containing left and right child of current node and key value ; Class to print the Diameter ; The function Compute the " height " of a tree . Height is the number of nodes along the longest path from the root node down to the farthest leaf node . ; base case tree is empty ; If tree is not empty then height = 1 + max of left height and right heights ; Method to calculate the diameter and return it to main ; base case if tree is empty ; get the height of left and right sub - trees ; get the diameter of left and right sub - trees ; Return max of following three 1 ) Diameter of left subtree 2 ) Diameter of right subtree 3 ) Height of left subtree + height of right subtree + 1 ; A wrapper over diameter ( Node root ) ; Driver Code ; creating a binary tree and entering the nodes ; Function Call
class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; static int height ( Node node ) { if ( node == null ) return 0 ; return ( 1 + Math . max ( height ( node . left ) , height ( node . right ) ) ) ; } int diameter ( Node root ) { if ( root == null ) return 0 ; int lheight = height ( root . left ) ; int rheight = height ( root . right ) ; int ldiameter = diameter ( root . left ) ; int rdiameter = diameter ( root . right ) ; return Math . max ( lheight + rheight + 1 , Math . max ( ldiameter , rdiameter ) ) ; } int diameter ( ) { return diameter ( root ) ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; System . out . println ( " The ▁ diameter ▁ of ▁ given ▁ binary ▁ tree ▁ is ▁ : ▁ " + tree . diameter ( ) ) ; } }
Find if possible to visit every nodes in given Graph exactly once based on given conditions | Java program for the above approach ; Function to find print path ; If a [ 0 ] is 1 ; Printing path ; Seeking for a [ i ] = 0 and a [ i + 1 ] = 1 ; Printing path ; If a [ N - 1 ] = 0 ; Driver Code ; Given Input ; Function Call
import java . io . * ; class GFG { static void findpath ( int N , int a [ ] ) { if ( a [ 0 ] == 1 ) { System . out . print ( ( N + 1 ) + " ▁ " ) ; for ( int i = 1 ; i <= N ; i ++ ) System . out . print ( ( i ) + " ▁ " ) ; return ; } for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( a [ i ] == 0 && a [ i + 1 ] == 1 ) { for ( int j = 1 ; j <= i ; j ++ ) System . out . print ( ( j ) + " ▁ " ) ; System . out . print ( ( N + 1 ) + " ▁ " ) ; for ( int j = i + 1 ; j <= N ; j ++ ) System . out . print ( ( j ) + " ▁ " ) ; return ; } } for ( int i = 1 ; i <= N ; i ++ ) System . out . print ( ( i ) + " ▁ " ) ; System . out . print ( ( N + 1 ) + " ▁ " ) ; } public static void main ( String [ ] args ) { int N = 3 , arr [ ] = { 0 , 1 , 0 } ; int N = 3 , arr [ ] = { 0 , 1 , 0 } ; findpath ( N , arr ) ; } }
Modify a numeric string to a balanced parentheses by replacements | Java program for the above approach ; Function to check if the given string can be converted to a balanced bracket sequence or not ; Check if the first and last characters are equal ; Initialize two variables to store the count of open and closed brackets ; If the current character is same as the first character ; If the current character is same as the last character ; If count of open brackets becomes less than 0 ; Print the new string ; If the current character is same as the first character ; If bracket sequence is not balanced ; Check for unbalanced bracket sequence ; Print the sequence ; Driver Code ; Given Input ; Function Call
import java . util . * ; class GFG { static void balBracketSequence ( String str ) { int n = str . length ( ) ; if ( str . charAt ( 0 ) == str . charAt ( n - 1 ) ) { System . out . println ( " No " ) ; } else { int cntForOpen = 0 , cntForClose = 0 ; int check = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == str . charAt ( 0 ) ) cntForOpen ++ ; else if ( str . charAt ( i ) == str . charAt ( n - 1 ) ) cntForOpen -= 1 ; else cntForOpen += 1 ; if ( cntForOpen < 0 ) { check = 0 ; break ; } } if ( check != 0 && cntForOpen == 0 ) { System . out . print ( " Yes , ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == str . charAt ( n - 1 ) ) System . out . print ( ' ) ' ) ; else System . out . print ( ' ( ' ) ; } return ; } else { for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == str . charAt ( 0 ) ) cntForClose ++ ; else cntForClose -- ; if ( cntForClose < 0 ) { check = 0 ; break ; } } if ( check != 0 && cntForClose == 0 ) { System . out . print ( " Yes , ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == str . charAt ( 0 ) ) System . out . print ( ' ( ' ) ; else System . out . print ( ' ) ' ) ; } return ; } } System . out . print ( " No " ) ; } } public static void main ( String args [ ] ) { String str = "123122" ; balBracketSequence ( str ) ; } }
Diameter of a Binary Tree | Class containing left and right child of current node and key value ; A utility class to pass heigh object ; Class to print the Diameter ; define height = 0 globally and call diameterOpt ( root , height ) from main ; lh -- > Height of left subtree rh -- > Height of right subtree ; base condition - when binary tree is empty ; diameter is also 0 ; ldiameter -- > diameter of left subtree rdiameter -- > Diameter of right subtree Get the heights of left and right subtrees in lh and rh . And store the returned values in ldiameter and ldiameter ; Height of current node is max of heights of left and right subtrees plus 1 ; A wrapper over diameter ( Node root ) ; The function Compute the " height " of a tree . Height is the number f nodes along the longest path from the root node down to the farthest leaf node . ; base case tree is empty ; If tree is not empty then height = 1 + max of left height and right heights ; Driver Code ; creating a binary tree and entering the nodes ; Function Call
class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } class Height { int h ; } class BinaryTree { Node root ; int diameterOpt ( Node root , Height height ) { Height lh = new Height ( ) , rh = new Height ( ) ; if ( root == null ) { height . h = 0 ; return 0 ; } int ldiameter = diameterOpt ( root . left , lh ) ; int rdiameter = diameterOpt ( root . right , rh ) ; height . h = Math . max ( lh . h , rh . h ) + 1 ; return Math . max ( lh . h + rh . h + 1 , Math . max ( ldiameter , rdiameter ) ) ; } int diameter ( ) { Height height = new Height ( ) ; return diameterOpt ( root , height ) ; } static int height ( Node node ) { if ( node == null ) return 0 ; return ( 1 + Math . max ( height ( node . left ) , height ( node . right ) ) ) ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; System . out . println ( " The ▁ diameter ▁ of ▁ given ▁ binary ▁ tree ▁ is ▁ : ▁ " + tree . diameter ( ) ) ; } }
Diameter of a Binary Tree in O ( n ) [ A new method ] | Simple Java program to find diameter of a binary tree . ; Tree node structure used in the program ; Function to find height of a tree ; update the answer , because diameter of a tree is nothing but maximum value of ( left_height + right_height + 1 ) for each node ; Computes the diameter of binary tree with given root . ; This will store the final answer ; A utility function to create a new Binary Tree Node ; Driver code
class GfG { static class Node { int data ; Node left , right ; } static class A { int ans = Integer . MIN_VALUE ; } static int height ( Node root , A a ) { if ( root == null ) return 0 ; int left_height = height ( root . left , a ) ; int right_height = height ( root . right , a ) ; a . ans = Math . max ( a . ans , 1 + left_height + right_height ) ; return 1 + Math . max ( left_height , right_height ) ; } static int diameter ( Node root ) { if ( root == null ) return 0 ; A a = new A ( ) ; int height_of_tree = height ( root , a ) ; return a . ans ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return ( node ) ; } public static void main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; System . out . println ( " Diameter ▁ is ▁ " + diameter ( root ) ) ; } }
Find postorder traversal of BST from preorder traversal | run loop from 1 to length of pre ; print from pivot length - 1 to zero ; print from end to pivot length ; Driver Code
import java . io . * ; class GFG { public void getPostOrderBST ( int pre [ ] ) { int pivotPoint = 0 ; for ( int i = 1 ; i < pre . length ; i ++ ) { if ( pre [ 0 ] <= pre [ i ] ) { pivotPoint = i ; break ; } } for ( int i = pivotPoint - 1 ; i > 0 ; i -- ) { System . out . print ( pre [ i ] + " ▁ " ) ; } for ( int i = pre . length - 1 ; i >= pivotPoint ; i -- ) { System . out . print ( pre [ i ] + " ▁ " ) ; } System . out . print ( pre [ 0 ] ) ; }
Count substrings made up of a single distinct character | Java program for the above approach ; Function to count the number of substrings made up of a single distinct character ; Stores the required count ; Stores the count of substrings possible by using current character ; Stores the previous character ; Traverse the string ; If current character is same as the previous character ; Increase count of substrings possible with current character ; Reset count of substrings possible with current character ; Update count of substrings ; Update previous character ; Driver Code
import java . io . * ; import java . util . * ; class GFG { static void countSubstrings ( String s ) { int ans = 0 ; int subs = 1 ; char pre = '0' ; for ( char i : s . toCharArray ( ) ) { if ( pre == i ) { subs += 1 ; } else { subs = 1 ; } ans += subs ; pre = i ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { String s = " geeksforgeeks " ; countSubstrings ( s ) ; } }
Generate an array from given pairs of adjacent elements | Java program of the above approach ; Utility function to find original array ; Map to store all neighbors for each element ; Vector to store original elements ; Stotrs which array elements are visited ; Adjacency list to store neighbors of each array element ; Find the first corner element ; Stores first element of the original array ; Push it into the original array ; Mark as visited ; Traversing the neighbors and check if the elements are visited or not ; Traverse adjacent elements ; If element is not visited ; Push it into res ; Mark as visited ; Update the next adjacent ; Print original array ; Driver Code ; Given pairs of adjacent elements
import java . io . * ; import java . util . * ; class Pair { int first , second ; Pair ( int first , int second ) { this . first = first ; this . second = second ; } } class GFG { static void find_original_array ( List < Pair > A ) { @ SuppressWarnings ( " unchecked " ) Map < Integer , List < Integer > > mp = new HashMap ( ) ; List < Integer > res = new ArrayList < Integer > ( ) ; @ SuppressWarnings ( " unchecked " ) Map < Integer , Boolean > visited = new HashMap ( ) ; for ( Pair it : A ) { List < Integer > temp ; temp = ( mp . containsKey ( it . first ) ) ? mp . get ( it . first ) : new ArrayList < Integer > ( ) ; temp . add ( it . second ) ; mp . put ( it . first , temp ) ; temp = ( mp . containsKey ( it . second ) ) ? mp . get ( it . second ) : new ArrayList < Integer > ( ) ; temp . add ( it . first ) ; mp . put ( it . second , temp ) ; } int it = 0 ; for ( Map . Entry < Integer , List < Integer > > entry : mp . entrySet ( ) ) { if ( entry . getValue ( ) . size ( ) == 1 ) { it = entry . getKey ( ) ; } } int adjacent = it ; res . add ( it ) ; visited . put ( it , true ) ; while ( res . size ( ) != A . size ( ) + 1 ) { for ( int elements : mp . get ( adjacent ) ) { if ( ! visited . containsKey ( elements ) ) { res . add ( elements ) ; visited . put ( elements , true ) ; adjacent = elements ; } } } for ( int val : res ) { System . out . print ( val + " ▁ " ) ; } } public static void main ( String [ ] args ) { @ SuppressWarnings ( " unchecked " ) List < Pair > A = new ArrayList ( ) ; A . add ( new Pair ( 5 , 1 ) ) ; A . add ( new Pair ( 3 , 4 ) ) ; A . add ( new Pair ( 3 , 5 ) ) ; find_original_array ( A ) ; } }
Possible edges of a tree for given diameter , height and vertices | Java program to construct tree for given count width and height . ; Function to construct the tree ; Special case when d == 2 , only one edge ; Tree is not possible ; Satisfy the height condition by add edges up to h ; Add d - h edges from 1 to satisfy diameter condition ; Remaining edges at vertex 1 or 2 ( d == h ) ; Driver Code
class GfG { static void constructTree ( int n , int d , int h ) { if ( d == 1 ) { if ( n == 2 && h == 1 ) { System . out . println ( "1 ▁ 2" ) ; return ; } System . out . println ( " - 1" ) ; return ; } if ( d > 2 * h ) { System . out . println ( " - 1" ) ; return ; } for ( int i = 1 ; i <= h ; i ++ ) System . out . println ( i + " ▁ " + ( i + 1 ) ) ; if ( d > h ) { System . out . println ( "1" + " ▁ " + ( h + 2 ) ) ; for ( int i = h + 2 ; i <= d ; i ++ ) { System . out . println ( i + " ▁ " + ( i + 1 ) ) ; } } for ( int i = d + 1 ; i < n ; i ++ ) { int k = 1 ; if ( d == h ) k = 2 ; System . out . println ( k + " ▁ " + ( i + 1 ) ) ; } } public static void main ( String [ ] args ) { int n = 5 , d = 3 , h = 2 ; constructTree ( n , d , h ) ; } }
Query to find length of the longest subarray consisting only of 1 s | Java Program for the above approach ; Function to calculate the longest subarray consisting of 1 s only ; Stores the maximum length of subarray containing 1 s only ; Traverse the array ; If current element is '1' ; Increment length ; Otherwise ; Reset length ; Update maximum subarray length ; Function to perform given queries ; Stores count of queries ; Traverse each query ; Flip the character ; Driver Code ; Size of array ; Given array ; Given queries ; Number of queries
import java . util . * ; public class Main { static int longestsubarray ( int a [ ] , int N ) { int maxlength = 0 , sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( a [ i ] == 1 ) { sum ++ ; } else { sum = 0 ; } maxlength = Math . max ( maxlength , sum ) ; } return maxlength ; } static void solveQueries ( int arr [ ] , int n , Vector < Vector < Integer > > Q , int k ) { int cntQuery = Q . size ( ) ; for ( int i = 0 ; i < cntQuery ; i ++ ) { if ( Q . get ( i ) . get ( 0 ) == 1 ) { System . out . print ( longestsubarray ( arr , n ) + " ▁ " ) ; } else { arr [ Q . get ( i ) . get ( 1 ) - 1 ] ^= 1 ; } } } public static void main ( String [ ] args ) { int N = 10 ; int arr [ ] = { 1 , 1 , 0 , 1 , 1 , 1 , 0 , 0 , 1 , 1 } ; Vector < Vector < Integer > > Q = new Vector < Vector < Integer > > ( ) ; Vector < Integer > v1 = new Vector < Integer > ( ) ; Vector < Integer > v2 = new Vector < Integer > ( ) ; Vector < Integer > v3 = new Vector < Integer > ( ) ; v1 . add ( 1 ) ; v2 . add ( 2 ) ; v2 . add ( 3 ) ; v3 . add ( 1 ) ; Q . add ( v1 ) ; Q . add ( v2 ) ; Q . add ( v3 ) ; int K = 3 ; solveQueries ( arr , N , Q , K ) ; } }