codeparrot/xlcost-text-to-code huggingface dataset:
Longest Substring of 1 's after removing one character | Java program to implement the above approach ; Function to calculate the length of the longest substring of '1' s that can be obtained by deleting one character ; Add '0' at the end ; Iterator to traverse the string ; Stores maximum length of required substring ; Stores length of substring of '1' preceding the current character ; Stores length of substring of '1' succeeding the current character ; Counts number of '0' s ; Traverse the string S ; If current character is '1' ; Increase curr_one by one ; Otherwise ; Increment numberofZeros by one ; Count length of substring obtained y concatenating preceding and succeeding substrings of '1' ; Store maximum size in res ; Assign curr_one to prev_one ; Reset curr_one ; If string contains only one '0' ; Return the answer ; Driver Code
import java . util . Arrays ; class GFG { static int longestSubarray ( String s ) { s += '0' ; int i ; int res = 0 ; int prev_one = 0 ; int curr_one = 0 ; int numberOfZeros = 0 ; for ( i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == '1' ) { curr_one += 1 ; } else { numberOfZeros += 1 ; prev_one += curr_one ; res = Math . max ( res , prev_one ) ; prev_one = curr_one ; curr_one = 0 ; } } if ( numberOfZeros == 1 ) { res -= 1 ; } return res ; } public static void main ( String [ ] args ) { String S = "1101" ; System . out . println ( longestSubarray ( S ) ) ; } }
Longest Substring of 1 's after removing one character | Java Program to implement the above approach ; Function to calculate the length of the longest subString of '1' s that can be obtained by deleting one character ; Initializing i and j as left and right boundaries of sliding window ; If current character is '0' ; Decrement k by one ; If k is less than zero and character at ith index is '0' ; Return result ; Driver Code
import java . util . * ; class GFG { static int longestSubarray ( String s ) { int i = 0 , j = 0 , k = 1 ; for ( j = 0 ; j < s . length ( ) ; ++ j ) { if ( s . charAt ( j ) == '0' ) k -- ; if ( k < 0 && s . charAt ( i ++ ) == '0' ) k ++ ; } return j - i - 1 ; } public static void main ( String [ ] args ) { String S = "011101101" ; System . out . print ( longestSubarray ( S ) ) ; } }
Lexicographically smallest string possible by inserting given character | Java program to implement the above approach ; Function to obtain lexicographically smallest String possible by inserting character c in the String s ; Traverse the String ; If the current character is greater than the given character ; Insert the character before the greater character ; Return the String ; Append the character at the end ; Return the String ; Driver Code
import java . util . * ; class GFG { static String SmallestString ( String s , char c ) { for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) > c ) { String temp = s ; s = s . substring ( 0 , i ) ; s += c ; s += temp . substring ( i , temp . length ( ) ) ; return s ; } } s += c ; return s ; } public static void main ( String args [ ] ) { String S = " acd " ; char C = ' b ' ; System . out . println ( SmallestString ( S , C ) ) ; } }
Largest Non | Java program to implement the above approach ; Function to find the largest unique element of the array ; Store frequency of each distinct element of the array ; Traverse the array ; Update frequency of arr [ i ] ; Stores largest non - repeating element present in the array ; Stores index of the largest non - repeating array element ; Traverse the array ; If frequency of arr [ i ] is equal to 1 and arr [ i ] exceeds LNRElem ; Update ind ; Update LNRElem ; If no array element is found with frequency equal to 1 ; Print largest non - repeating element ; Driver Code
import java . io . * ; import java . util . * ; class GFG { static void LarUnEl ( int arr [ ] , int N ) { HashMap < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { map . put ( arr [ i ] , map . getOrDefault ( arr [ i ] , 0 ) + 1 ) ; } int LNRElem = Integer . MIN_VALUE ; int ind = - 1 ; for ( int i = 0 ; i < N ; i ++ ) { if ( map . get ( arr [ i ] ) == 1 && arr [ i ] > LNRElem ) { ind = i ; LNRElem = arr [ i ] ; } } if ( ind == - 1 ) { System . out . println ( ind ) ; return ; } System . out . println ( arr [ ind ] ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 3 , 1 , 8 , 8 , 4 } ; int N = arr . length ; LarUnEl ( arr , N ) ; } }
Minimum shifts of substrings of 1 s required to group all 1 s together in a given Binary string | Java program for the above approach ; Function to count indices substrings of 1 s need to be shifted such that all 1 s in the string are grouped together ; Stores first occurrence of '1' ; Stores last occurrence of '1' ; Count of 0 s between firstOne and lastOne ; Traverse the string to find the first and last occurrences of '1' ; Count number of 0 s present between firstOne and lastOne ; Print minimum operations ; Driver code ; Given string
import java . io . * ; import java . util . * ; class GFG { static void countShifts ( String str ) { int firstOne = - 1 ; int lastOne = - 1 ; int count = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == '1' ) { if ( firstOne == - 1 ) firstOne = i ; lastOne = i ; } } if ( ( firstOne == - 1 ) || ( firstOne == lastOne ) ) { System . out . print ( 0 ) ; return ; } for ( int i = firstOne ; i <= lastOne ; i ++ ) { if ( str . charAt ( i ) == '0' ) { count ++ ; } } System . out . println ( count ) ; } public static void main ( String [ ] args ) { String str = "00110111011" ; countShifts ( str ) ; } }
Check if a non | Java program for the above approach ; Utility Function to check whether a subsequence same as the given subarray exists or not ; Check if first element of the subarray is also present before ; Check if last element of the subarray is also present later ; If above two conditions are not satisfied , then no such subsequence exists ; Function to check and print if a subsequence which is same as the given subarray is present or not ; Driver code ; Function Call
class GFG { static boolean checkSubsequenceUtil ( int arr [ ] , int L , int R , int N ) { for ( int i = 0 ; i < L ; i ++ ) if ( arr [ i ] == arr [ L ] ) return true ; for ( int i = R + 1 ; i < N ; i ++ ) if ( arr [ i ] == arr [ R ] ) return true ; return false ; } static void checkSubsequence ( int arr [ ] , int L , int R , int N ) { if ( checkSubsequenceUtil ( arr , L , R , N ) ) { System . out . print ( "YESNEW_LINE"); } else { System . out . print ( "NONEW_LINE"); } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 7 , 12 , 1 , 7 , 5 , 10 , 11 , 42 } ; int N = arr . length ; int L = 3 , R = 6 ; checkSubsequence ( arr , L , R , N ) ; } }
Search an element in a Doubly Linked List | Java program to implement the above approach ; Structure of a node of the doubly linked list ; Stores data value of a node ; Stores pointer to next node ; Stores pointer to previous node ; Function to insert a node at the beginning of the Doubly Linked List ; Allocate memory for new node ; Insert the data ; Since node is added at the beginning , prev is always null ; Link the old list to the new node ; If pointer to head is not null ; Change the prev of head node to new node ; Move the head to point to the new node ; Function to find the position of an integer in doubly linked list ; Stores head Node ; Stores position of the integer in the doubly linked list ; Traverse the doubly linked list ; Update pos ; Update temp ; If the integer not present in the doubly linked list ; If the integer present in the doubly linked list ; Driver Code ; Create the doubly linked list 18 < -> 15 < -> 8 < -> 9 < -> 14
import java . util . * ; class GFG { static class Node { int data ; Node next ; Node prev ; } ; static Node push ( Node head_ref , int new_data ) { Node new_node = new Node ( ) ; new_node . data = new_data ; new_node . prev = null ; new_node . next = head_ref ; if ( head_ref != null ) { head_ref . prev = new_node ; } head_ref = new_node ; return head_ref ; } static int search ( Node head_ref , int x ) { Node temp = head_ref ; int pos = 0 ; while ( temp . data != x && temp . next != null ) { pos ++ ; temp = temp . next ; } if ( temp . data != x ) return - 1 ; return ( pos + 1 ) ; } public static void main ( String [ ] args ) { Node head = null ; int X = 8 ; head = push ( head , 14 ) ; head = push ( head , 9 ) ; head = push ( head , 8 ) ; head = push ( head , 15 ) ; head = push ( head , 18 ) ; System . out . print ( search ( head , X ) ) ; } }
Longest subarray in which all elements are smaller than K | Java program for the above approach ; Function to find the length of the longest subarray with all elements smaller than K ; Stores the length of maximum consecutive sequence ; Stores maximum length of subarray ; Iterate through the array ; Check if array element smaller than K ; Store the maximum of length and count ; Reset the counter ; Print the maximum length ; Driver code ; Given array arr [ ] ; Size of the array ; Given K ; Function Call
import java . util . * ; class GFG { static void largestSubarray ( int [ ] arr , int N , int K ) { int count = 0 ; int len = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < K ) { count += 1 ; } else { len = Math . max ( len , count ) ; count = 0 ; } } if ( count != 0 ) { len = Math . max ( len , count ) ; } System . out . println ( len ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 8 , 3 , 5 , 2 , 2 , 1 , 13 } ; int N = arr . length ; int K = 6 ; largestSubarray ( arr , N , K ) ; } }
Smallest pair of indices with product of subarray co | Java program for the above approach ; Function to calculate GCD of two integers ; Recursively calculate GCD ; Function to find the lexicographically smallest pair of indices whose product is co - prime with the product of the subarrays on its left and right ; Stores the suffix product of array elements ; Set 0 / 1 if pair satisfies the given condition or not ; Initialize array right_prod [ ] ; Update the suffix product ; Stores product of all elements ; Stores the product of subarray in between the pair of indices ; Iterate through every pair of indices ( i , j ) ; Store product of A [ i , j ] ; Check if product is co - prime to product of either the left or right subarrays ; If no such pair is found , then print - 1 ; Driver Code ; Function Call
import java . util . * ; class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static void findPair ( int A [ ] , int N ) { int right_prod [ ] = new int [ N ] ; int flag = 0 ; right_prod [ N - 1 ] = A [ N - 1 ] ; for ( int i = N - 2 ; i >= 0 ; i -- ) right_prod [ i ] = right_prod [ i + 1 ] * A [ i ] ; int total_prod = right_prod [ 0 ] ; int product ; for ( int i = 1 ; i < N - 1 ; i ++ ) { product = 1 ; for ( int j = i ; j < N - 1 ; j ++ ) { product *= A [ j ] ; if ( gcd ( product , right_prod [ j + 1 ] ) == 1 || gcd ( product , total_prod / right_prod [ i ] ) == 1 ) { flag = 1 ; System . out . println ( " ( " + ( i - 1 ) + " , ▁ " + ( j + 1 ) + " ) " ) ; break ; } } if ( flag == 1 ) break ; } if ( flag == 0 ) System . out . print ( - 1 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 1 , 3 , 7 } ; int N = arr . length ; findPair ( arr , N ) ; } }
Count binary strings of length same as given string after removal of substrings "01" and "00" that consists of at least one '1' | Java program for the above approach ; Function to count the strings consisting of at least 1 set bit ; Initialize count ; Iterate through string ; The answer is 2 ^ N - 1 ; Driver Code ; Given string ; Function call
import java . util . * ; class GFG { static void countString ( String S ) { int count = 0 ; for ( char it : S . toCharArray ( ) ) { if ( it == '0' && count > 0 ) { count -- ; } else { count ++ ; } } System . out . print ( ( 1 << count ) - 1 ) ; } public static void main ( String [ ] args ) { String S = "1001" ; countString ( S ) ; } }
Append digits to the end of duplicate strings to make all strings in an array unique | Java program for the above approach ; Function to replace duplicate strings by alphanumeric strings to make all strings in the array unique ; Store the frequency of strings ; Iterate over the array ; For the first occurrence , update the frequency count ; Otherwise ; Append frequency count to end of the string ; Print the modified array ; Driver Code ; Function Call
import java . io . * ; import java . util . * ; class GFG { static void replaceDuplicates ( String [ ] names ) { HashMap < String , Integer > hash = new HashMap < > ( ) ; for ( int i = 0 ; i < names . length ; i ++ ) { if ( ! hash . containsKey ( names [ i ] ) ) hash . put ( names [ i ] , 1 ) ; else { int count = hash . get ( names [ i ] ) ; hash . put ( names [ i ] , hash . get ( names [ i ] ) + 1 ) ; names [ i ] += Integer . toString ( count ) ; } } for ( int i = 0 ; i < names . length ; i ++ ) { System . out . print ( names [ i ] + ' ▁ ' ) ; } } public static void main ( String [ ] args ) { String [ ] str = { " aa " , " bb " , " cc " , " bb " , " aa " , " aa " , " aa " } ; replaceDuplicates ( str ) ; } }
Minimum cost of flipping characters required to convert Binary String to 0 s only | Java program to implement the above approach ; Function to find the minimum cost to convert given string to 0 s only ; Length of string ; Stores the index of leftmost '1' in str ; Update the index of leftmost '1' in str ; Stores the index of rightmost '1' in str ; Update the index of rightmost '1' in str ; If str does not contain any '1' s ; No changes required ; Stores minimum cost ; Iterating through str form left_1 to right_1 ; Stores length of consecutive 0 s ; Calculate length of consecutive 0 s ; If a substring of 0 s exists ; Update minimum cost ; Printing the minimum cost ; Driver code
class GFG { public static void convert_to_allzeroes ( String str , int a , int b ) { int len = str . length ( ) ; int left_1 , i = 0 ; while ( i < len && str . charAt ( i ) == '0' ) i ++ ; left_1 = i ; int right_1 ; i = len - 1 ; while ( i >= 0 && str . charAt ( i ) == '0' ) i -- ; right_1 = i ; if ( left_1 == len && right_1 == - 1 ) { System . out . print ( 0 ) ; return ; } int cost = a , zeroes ; for ( i = left_1 ; i <= right_1 ; i ++ ) { zeroes = 0 ; while ( i < len && str . charAt ( i ) == '0' ) { zeroes ++ ; i ++ ; } if ( zeroes != 0 ) cost += Math . min ( zeroes * b , a ) ; } System . out . print ( cost ) ; } public static void main ( String [ ] args ) { String str = "01101110" ; int A = 5 , B = 1 ; convert_to_allzeroes ( str , A , B ) ; } }
Minimum distance to visit given K points on X | Java program to implement the above approach ; Function to find the minimum distance travelled to visit K point ; Stores minimum distance travelled to visit K point ; Stores distance travelled to visit points ; Traverse the array arr [ ] ; If arr [ i ] and arr [ i + K - 1 ] are positive ; Update dist ; Update dist ; Update res ; Driver Code ; initial the array
import java . util . * ; class solution { static int MinDistK ( int arr [ ] , int N , int K ) { int res = Integer . MAX_VALUE ; int dist = 0 ; for ( int i = 0 ; i <= ( N - K ) ; i ++ ) { if ( arr [ i ] >= 0 && arr [ i + K - 1 ] >= 0 ) { dist = Math . max ( arr [ i ] , arr [ i + K - 1 ] ) ; } else { dist = Math . abs ( arr [ i ] ) + Math . abs ( arr [ i + K - 1 ] ) + Math . min ( Math . abs ( arr [ i ] ) , Math . abs ( arr [ i + K - 1 ] ) ) ; } res = Math . min ( res , dist ) ; } return res ; } public static void main ( String args [ ] ) { int K = 3 ; int arr [ ] = { - 30 , - 10 , 10 , 20 , 50 } ; int N = arr . length ; System . out . println ( MinDistK ( arr , N , K ) ) ; } }
Maximize the minimum array element by M subarray increments of size S | Java program for the above approach ; Function to return index of minimum element in the array ; Initialize a [ 0 ] as minValue ; Traverse the array ; If a [ i ] < existing minValue ; Return the minimum index ; Function that maximize the minimum element of array after incrementing subarray of size S by 1 , M times ; Iterating through the array or M times ; Find minimum element index ; Increment the minimum value ; Storing the left index and right index ; Incrementing S - 1 minimum elements to the left and right of minValue ; Reached extreme left ; Reached extreme right ; Left value is minimum ; Right value is minimum ; Find the minValue in A [ ] after M operations ; Return the minimum value ; Driver Code ; Function Call
import java . util . * ; class solution { static int min1 ( int a [ ] , int n ) { int minIndex = 0 , minValue = a [ 0 ] , i ; for ( i = 1 ; i < n ; i ++ ) { if ( a [ i ] < minValue ) { minValue = a [ i ] ; minIndex = i ; } } return minIndex ; } static int maximizeMin ( int A [ ] , int N , int S , int M ) { int minIndex , left , right , i , j ; for ( i = 0 ; i < M ; i ++ ) { minIndex = min1 ( A , N ) ; A [ minIndex ] ++ ; left = minIndex - 1 ; right = minIndex + 1 ; for ( j = 0 ; j < S - 1 ; j ++ ) { if ( left == - 1 ) A [ right ++ ] ++ ; else if ( right == N ) A [ left -- ] ++ ; else { if ( A [ left ] < A [ right ] ) A [ left -- ] ++ ; else A [ right ++ ] ++ ; } } } minIndex = min1 ( A , N ) ; return A [ minIndex ] ; } public static void main ( String args [ ] ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 , 6 } ; int N = arr . length ; int S = 2 , M = 3 ; System . out . print ( maximizeMin ( arr , N , S , M ) ) ; } }
Sum of nodes in the path from root to N | Java program for the above approach ; Function to find sum of aint nodes from root to N ; If N is equal to 1 ; If N is equal to 2 or 3 ; Stores the number of nodes at ( i + 1 ) - th level ; Stores the number of nodes ; Stores if the current level is even or odd ; If level is odd ; If level is even ; If level with node N is reached ; Push into vector ; Compute prefix sums of count of nodes in each level ; Stores the level in which node N s present ; Stores the required sum ; Add temp to the sum ; Driver Code ; Function Call
import java . util . * ; class GFG { static int sumOfPathNodes ( int N ) { if ( N == 1 ) { return 1 ; } else if ( N == 2 N == 3 ) { return N + 1 ; } Vector < Integer > arr = new Vector < > ( ) ; arr . add ( 1 ) ; int k = 1 ; boolean flag = true ; while ( k < N ) { if ( flag == true ) { k *= 2 ; flag = false ; } else { k *= 4 ; flag = true ; } if ( k > N ) { break ; } arr . add ( k ) ; } int len = arr . size ( ) ; int [ ] prefix = new int [ len ] ; prefix [ 0 ] = 1 ; for ( int i = 1 ; i < len ; ++ i ) { prefix [ i ] = arr . get ( i ) + prefix [ i - 1 ] ; } int it = lowerBound ( prefix , 0 , len , N ) + 1 ; int ind = it - prefix [ 0 ] ; int final_ans = 0 ; int temp = N ; while ( ind > 1 ) { int val = temp - prefix [ ind - 1 ] ; if ( ind % 2 != 0 ) { temp = prefix [ ind - 2 ] + ( val + 1 ) / 2 ; } else { temp = prefix [ ind - 2 ] + ( val + 3 ) / 4 ; } -- ind ; final_ans += temp ; } final_ans += ( N + 1 ) ; return final_ans ; } static int lowerBound ( int [ ] a , int low , int high , int element ) { while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } public static void main ( String [ ] args ) { int N = 13 ; System . out . print ( sumOfPathNodes ( N ) + "NEW_LINE"); } }
Check if given point lies in range of any of the given towers | Java program to implement the above approach ; Function to check if the point ( X , Y ) exists in the towers network - range or not ; Traverse the array arr [ ] ; Stores distance of the point ( X , Y ) from i - th tower ; If dist lies within the range of the i - th tower ; If the point ( X , Y ) does not lie in the range of any of the towers ; Driver Code ; If point ( X , Y ) lies in the range of any of the towers ; Otherwise
import java . util . * ; class GFG { static boolean checkPointRange ( int arr [ ] [ ] , int X , int Y , int N ) { for ( int i = 0 ; i < N ; i ++ ) { double dist = Math . sqrt ( ( arr [ i ] [ 0 ] - X ) * ( arr [ i ] [ 0 ] - X ) + ( arr [ i ] [ 1 ] - Y ) * ( arr [ i ] [ 1 ] - Y ) ) ; if ( dist <= arr [ i ] [ 2 ] ) { return true ; } } return false ; } public static void main ( String [ ] args ) { int arr [ ] [ ] = { { 1 , 1 , 3 } , { 10 , 10 , 3 } , { 15 , 15 , 15 } } ; int X = 5 , Y = 5 ; int N = arr . length ; if ( checkPointRange ( arr , X , Y , N ) ) { System . out . print ( " True " ) ; } else { System . out . print ( " False " ) ; } } }
Find the winner of the Game of removing odd or replacing even array elements | Java program for the above approach ; Function to evaluate the winner of the game ; Stores count of odd array elements ; Stores count of even array elements ; Traverse the array ; If array element is odd ; Otherwise ; If count of even is zero ; If count of odd is even ; If count of odd is odd ; If count of odd is odd and count of even is one ; Otherwise ; Driver Code
import java . util . * ; class GFG { static void findWinner ( int arr [ ] , int N ) { int odd = 0 ; int even = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 1 ) { odd ++ ; } else { even ++ ; } } if ( even == 0 ) { if ( odd % 2 == 0 ) { System . out . println ( " Player ▁ 2" ) ; } else if ( odd % 2 == 1 ) { System . out . println ( " Player ▁ 1" ) ; } } else if ( even == 1 && odd % 2 == 1 ) { System . out . println ( " Player ▁ 1" ) ; } else { System . out . println ( - 1 ) ; } } public static void main ( String args [ ] ) { int arr [ ] = { 3 , 1 , 9 , 7 } ; int N = arr . length ; findWinner ( arr , N ) ; } }
Rearrange array to maximize count of local minima | Java program to implement the above approach ; Function to rearrange array elements to maximize count of local minima in the array ; Sort the array in ascending order ; Stores index of left pointer ; Stores index of right pointer ; Traverse the array elements ; If right is less than N ; Print array element ; Update right ; Print array element ; Update left ; Driver Code
import java . util . * ; class GFG { static void rearrangeArrMaxcntMinima ( int arr [ ] , int N ) { Arrays . sort ( arr ) ; int left = 0 ; int right = N / 2 ; while ( left < N / 2 right < N ) { if ( right < N ) { System . out . print ( arr [ right ] + " ▁ " ) ; right ++ ; } if ( left < N / 2 ) { System . out . print ( arr [ left ] + " ▁ " ) ; left ++ ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int N = arr . length ; rearrangeArrMaxcntMinima ( arr , N ) ; } }
Minimum jumps required to make a group of persons sit together | Java program for the above approach ; Function to find the minimum jumps required to make the whole group sit adjacently ; Store the indexes ; Stores the count of occupants ; Length of the String ; Traverse the seats ; If current place is occupied ; Push the current position in the vector ; Base Case : ; The index of the median element ; The value of the median element ; Traverse the position [ ] ; Update the ans ; Return the final count ; Driver Code ; Given arrange of seats ; Function Call
import java . util . * ; class GFG { static int MOD = ( int ) 1e9 + 7 ; static int minJumps ( String seats ) { Vector < Integer > position = new Vector < > ( ) ; int count = 0 ; int len = seats . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( seats . charAt ( i ) == ' x ' ) { position . add ( i - count ) ; count ++ ; } } if ( count == len count == 0 ) return 0 ; int med_index = ( count - 1 ) / 2 ; int med_val = position . get ( med_index ) ; int ans = 0 ; for ( int i = 0 ; i < position . size ( ) ; i ++ ) { ans = ( ans % MOD + Math . abs ( position . get ( i ) - med_val ) % MOD ) % MOD ; } return ans % MOD ; } public static void main ( String [ ] args ) { String S = " . . . . x . . xx . . . x . . " ; System . out . print ( minJumps ( S ) ) ; } }