id
int64
0
1.17k
comefrom
stringlengths
21
84
code
stringlengths
50
1.89k
masked
stringlengths
63
2.42k
unique_words_num
int64
0
6
words
stringlengths
1
139
1,128
<gouthampradhan>math_ReachingPoints_1.java
private int[] reduce(int x, int y) { int t = x - y; int q = t / y; x -= (y * q); if ((t % y) != 0) { x -= y; } return new int[] {x, y}; }
private int [ ] sample_funcname ( int var_0 , int var_1 ) { int var_2 = var_0 - var_1 ; int var_3 = var_2 / var_1 ; var_0 -= ( var_1 * var_3 ) ; if ( ( var_2 % var_1 ) != 0 ) { var_0 -= var_1 ; } return new int [ ] { var_0 , var_1 }; }
1
0
1,129
<gouthampradhan>dynamic_programming_LargestPlusSign_1.java
public int orderOfLargestPlusSign(int N, int[][] mines) { int[][] A = new int[N][N]; int[][] B = new int[N][N]; for (int[] row : mines) { int r = row[0]; int c = row[1]; A[r][c] = 1; } for (int i = 0; i < A.length; i++) { for (int j = 0; j < A[0].length; j++) { if (A[i][j] == 0) { A[i][j] = 1; } else { A[i][j] = 0; } B[i][j] = Integer.MAX_VALUE; } } for (int i = 0; i < A.length; i++) { int prev = 0; for (int j = 0; j < A[0].length; j++) { if (A[i][j] == 0) { prev = 0; B[i][j] = 0; } else { prev++; B[i][j] = Math.min(B[i][j], prev); } } prev = 0; for (int j = N - 1; j >= 0; j--) { if (A[i][j] == 0) { prev = 0; B[i][j] = 0; } else { prev++; B[i][j] = Math.min(B[i][j], prev); } } } for (int j = 0; j < B[0].length; j++) { int prev = 0; for (int i = 0; i < B.length; i++) { if (A[i][j] == 0) { prev = 0; B[i][j] = 0; } else { prev++; B[i][j] = Math.min(B[i][j], prev); } } prev = 0; for (int i = N - 1; i >= 0; i--) { if (A[i][j] == 0) { prev = 0; B[i][j] = 0; } else { prev++; B[i][j] = Math.min(B[i][j], prev); } } } int result = 0; for (int i = 0; i < B.length; i++) { for (int j = 0; j < B[0].length; j++) { result = Math.max(result, B[i][j]); } } return result; }
public int sample_funcname ( int var_0 , int [ ] [ ] var_1 ) { int [ ] [ ] var_2 = new int [ var_0 ] [ var_0 ] ; int [ ] [ ] var_3 = new int [ var_0 ] [ var_0 ] ; for ( int [ ] var_4 : var_1 ) { int var_5 = var_4 [ 0 ] ; int var_6 = var_4 [ 1 ] ; var_2 [ var_5 ] [ var_6 ] = 1 ; } for ( int var_7 = 0 ; var_7 < var_2 . length ; var_7 ++ ) { for ( int var_8 = 0 ; var_8 < var_2 [ 0 ] . length ; var_8 ++ ) { if ( var_2 [ var_7 ] [ var_8 ] == 0 ) { var_2 [ var_7 ] [ var_8 ] = 1 ; } else { var_2 [ var_7 ] [ var_8 ] = 0 ; } var_3 [ var_7 ] [ var_8 ] = Integer . MAX_VALUE ; } } for ( int var_7 = 0 ; var_7 < var_2 . length ; var_7 ++ ) { int var_9 = 0 ; for ( int var_8 = 0 ; var_8 < var_2 [ 0 ] . length ; var_8 ++ ) { if ( var_2 [ var_7 ] [ var_8 ] == 0 ) { var_9 = 0 ; var_3 [ var_7 ] [ var_8 ] = 0 ; } else { var_9 ++ ; var_3 [ var_7 ] [ var_8 ] = Math . min ( var_3 [ var_7 ] [ var_8 ] , var_9 ) ; } } var_9 = 0 ; for ( int var_8 = var_0 - 1 ; var_8 >= 0 ; var_8 -- ) { if ( var_2 [ var_7 ] [ var_8 ] == 0 ) { var_9 = 0 ; var_3 [ var_7 ] [ var_8 ] = 0 ; } else { var_9 ++ ; var_3 [ var_7 ] [ var_8 ] = Math . min ( var_3 [ var_7 ] [ var_8 ] , var_9 ) ; } } } for ( int var_8 = 0 ; var_8 < var_3 [ 0 ] . length ; var_8 ++ ) { int var_9 = 0 ; for ( int var_7 = 0 ; var_7 < var_3 . length ; var_7 ++ ) { if ( var_2 [ var_7 ] [ var_8 ] == 0 ) { var_9 = 0 ; var_3 [ var_7 ] [ var_8 ] = 0 ; } else { var_9 ++ ; var_3 [ var_7 ] [ var_8 ] = Math . min ( var_3 [ var_7 ] [ var_8 ] , var_9 ) ; } } var_9 = 0 ; for ( int var_7 = var_0 - 1 ; var_7 >= 0 ; var_7 -- ) { if ( var_2 [ var_7 ] [ var_8 ] == 0 ) { var_9 = 0 ; var_3 [ var_7 ] [ var_8 ] = 0 ; } else { var_9 ++ ; var_3 [ var_7 ] [ var_8 ] = Math . min ( var_3 [ var_7 ] [ var_8 ] , var_9 ) ; } } } int var_10 = 0 ; for ( int var_7 = 0 ; var_7 < var_3 . length ; var_7 ++ ) { for ( int var_8 = 0 ; var_8 < var_3 [ 0 ] . length ; var_8 ++ ) { var_10 = Math . max ( var_10 , var_3 [ var_7 ] [ var_8 ] ) ; } } return var_10 ; }
2
0<SEP>1
1,130
<gouthampradhan>stack_DecodeString_1.java
public String decodeString(String s) { Stack<Character> stack = new Stack<>(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == ']') { StringBuilder stackBuff = new StringBuilder(); while (stack.peek() != '[') { stackBuff.append(stack.pop()); } stack.pop(); String num = ""; while (!stack.isEmpty() && !Character.isAlphabetic(stack.peek()) && stack.peek() != '[') { num = stack.pop() + num; } String str = stackBuff.reverse().toString(); StringBuilder stringMultiple = new StringBuilder(); int N = Integer.parseInt(num); while (N-- > 0) { stringMultiple.append(str); } for (int j = 0; j < stringMultiple.length(); j++) { stack.push(stringMultiple.charAt(j)); } } else stack.push(s.charAt(i)); } StringBuilder result = new StringBuilder(); while (!stack.isEmpty()) { result.append(stack.pop()); } return result.reverse().toString(); }
public String var_0 ( String var_1 ) { Stack < Character > var_2 = new Stack < > ( ) ; for ( int var_3 = 0 ; var_3 < var_1 . length ( ) ; var_3 ++ ) { if ( var_1 . charAt ( var_3 ) == ']' ) { StringBuilder var_4 = new StringBuilder ( ) ; while ( var_2 . peek ( ) != '[' ) { var_4 . append ( var_2 . pop ( ) ) ; } var_2 . pop ( ) ; String var_5 = "" ; while ( ! var_2 . isEmpty ( ) && ! Character . isAlphabetic ( var_2 . peek ( ) ) && var_2 . peek ( ) != '[' ) { var_5 = var_2 . pop ( ) + var_5 ; } String var_6 = var_4 . reverse ( ) . toString ( ) ; StringBuilder var_7 = new StringBuilder ( ) ; int var_8 = Integer . parseInt ( var_5 ) ; while ( var_8 -- > 0 ) { var_7 . append ( var_6 ) ; } for ( int var_9 = 0 ; var_9 < var_7 . length ( ) ; var_9 ++ ) { var_2 . push ( var_7 . charAt ( var_9 ) ) ; } } else var_2 . push ( var_1 . charAt ( var_3 ) ) ; } StringBuilder var_10 = new StringBuilder ( ) ; while ( ! var_2 . isEmpty ( ) ) { var_10 . append ( var_2 . pop ( ) ) ; } return var_10 . reverse ( ) . toString ( ) ; }
4
<D_QUOTE><D_QUOTE><SEP>0<SEP><S_QUOTE>[<S_QUOTE><SEP><S_QUOTE>]<S_QUOTE>
1,131
<gouthampradhan>dynamic_programming_OddEvenJump_1.java
private int dp(int[] A, int i, int[][] next, int[][] possible, int oddOrEven) { if (i == A.length - 1) return 1; else if (possible[oddOrEven][i] == 1 || possible[oddOrEven][i] == 0) { return possible[oddOrEven][i]; } else { int nextPos = oddOrEven == 0 ? next[0][i] : next[1][i]; if (nextPos == -1) { possible[oddOrEven][i] = 0; return possible[oddOrEven][i]; } else { possible[oddOrEven][i] = dp(A, nextPos, next, possible, ((oddOrEven + 1) % 2)); return possible[oddOrEven][i]; } } }
private int sample_funcname ( int [ ] A , int i , int [ ] [ ] next , int [ ] [ ] possible , int oddOrEven ) { if ( i == A . length - 1 ) return 1 ; else if ( possible [ oddOrEven ] [ i ] == 1 || possible [ oddOrEven ] [ i ] == 0 ) { return possible [ oddOrEven ] [ i ] ; } else { int nextPos = oddOrEven == 0 ? next [ 0 ] [ i ] : next [ 1 ] [ i ] ; if ( nextPos == - 1 ) { possible [ oddOrEven ] [ i ] = 0 ; return possible [ oddOrEven ] [ i ] ; } else { possible [ oddOrEven ] [ i ] = dp ( A , nextPos , next , possible , ( ( oddOrEven + 1 ) % 2 ) ) ; return possible [ oddOrEven ] [ i ] ; } } }
3
1<SEP>0<SEP>2
1,133
<gouthampradhan>stack_LargestRectangleInHistogram_1.java
public int largestRectangleArea(int[] heights) { if (heights.length == 0) return 0; int maxArea = Integer.MIN_VALUE; Stack<Integer> stack = new Stack<>(); int i = 0; for (; i < heights.length; i++) { while (!stack.isEmpty() && heights[stack.peek()] >= heights[i]) { int top = stack.pop(); int base = stack.isEmpty() ? i : i - stack.peek() - 1; maxArea = Math.max(maxArea, base * heights[top]); } stack.push(i); } while (!stack.isEmpty()) { int top = stack.pop(); int base = stack.isEmpty() ? i : i - stack.peek() - 1; maxArea = Math.max(maxArea, base * heights[top]); } return maxArea; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 . length == 0 ) return 0 ; int var_1 = Integer . MIN_VALUE ; Stack < Integer > var_2 = new Stack < > ( ) ; int var_3 = 0 ; for ( ; var_3 < var_0 . length ; var_3 ++ ) { while ( ! var_2 . isEmpty ( ) && var_0 [ var_2 . peek ( ) ] >= var_0 [ var_3 ] ) { int var_4 = var_2 . pop ( ) ; int var_5 = var_2 . isEmpty ( ) ? var_3 : var_3 - var_2 . peek ( ) - 1 ; var_1 = Math . max ( var_1 , var_5 * var_0 [ var_4 ] ) ; } var_2 . push ( var_3 ) ; } while ( ! var_2 . isEmpty ( ) ) { int var_4 = var_2 . pop ( ) ; int var_5 = var_2 . isEmpty ( ) ? var_3 : var_3 - var_2 . peek ( ) - 1 ; var_1 = Math . max ( var_1 , var_5 * var_0 [ var_4 ] ) ; } return var_1 ; }
2
0<SEP>1
1,134
<gouthampradhan>hashing_DistributeCandies_1.java
public int distributeCandies(int[] candies) { int N = candies.length; Set<Integer> set = new HashSet<>(); for (int c : candies) { set.add(c); } int n = set.size(); return Math.min(N / 2, set.size()); }
public int sample_funcname ( int [ ] var_0 ) { int var_1 = var_0 . length ; Set < Integer > var_2 = new HashSet < > ( ) ; for ( int var_3 : var_0 ) { var_2 . add ( var_3 ) ; } int var_4 = var_2 . size ( ) ; return Math . min ( var_1 / 2 , var_2 . size ( ) ) ; }
1
2
1,135
<gouthampradhan>greedy_PartitionLabels_1.java
public List<Integer> partitionLabels(String S) { Map<Character, Integer> map = new HashMap<>(); for (int i = 0; i < S.length(); i++) { char c = S.charAt(i); map.putIfAbsent(c, i); map.remove(c); map.put(c, i); } char start = S.charAt(0); int currMax = map.get(start); int startIndex = 0; List<Integer> list = new ArrayList<>(); while (true) { int i = startIndex; for (; i <= currMax; i++) { char c = S.charAt(i); int pos = map.get(c); currMax = Math.max(currMax, pos); } if (i > currMax && i < S.length()) { list.add(i - startIndex); startIndex = i; currMax = map.get(S.charAt(i)); } else { if (i == S.length()) { list.add(i - startIndex); break; } } } return list; }
public List < Integer > var_0 ( String var_1 ) { Map < Character , Integer > var_2 = new HashMap < > ( ) ; for ( int var_3 = 0 ; var_3 < var_1 . length ( ) ; var_3 ++ ) { char var_4 = var_1 . charAt ( var_3 ) ; var_2 . putIfAbsent ( var_4 , var_3 ) ; var_2 . remove ( var_4 ) ; var_2 . put ( var_4 , var_3 ) ; } char var_5 = var_1 . charAt ( 0 ) ; int var_6 = var_2 . get ( var_5 ) ; int var_7 = 0 ; List < Integer > var_8 = new ArrayList < > ( ) ; while ( true ) { int var_3 = var_7 ; for ( ; var_3 <= var_6 ; var_3 ++ ) { char var_4 = var_1 . charAt ( var_3 ) ; int var_9 = var_2 . get ( var_4 ) ; var_6 = Math . max ( var_6 , var_9 ) ; } if ( var_3 > var_6 && var_3 < var_1 . length ( ) ) { var_8 . add ( var_3 - var_7 ) ; var_7 = var_3 ; var_6 = var_2 . get ( var_1 . charAt ( var_3 ) ) ; } else { if ( var_3 == var_1 . length ( ) ) { var_8 . add ( var_3 - var_7 ) ; break ; } } } return var_8 ; }
1
0
1,136
<gouthampradhan>array_MinimumSwapsToGroupAll1Together_1.java
public int minSwaps(int[] data) { int one = 0; int zero = 0; for (int i = 0; i < data.length; i++) { if (data[i] == 1) { one++; } else zero++; } if (one == 0) return 0; int window = one; one = 0; zero = 0; int i = 0, j = window - 1; for (int k = i; k <= j; k++) { if (data[k] == 1) { one++; } else zero++; } i++; j++; int min = zero; for (; j < data.length; i++, j++) { if (data[j] == 0) { zero++; } else one++; if (data[i - 1] == 0) { zero--; } else one--; min = Math.min(min, zero); } return min; }
public int sample_funcname ( int [ ] var_0 ) { int var_1 = 0 ; int var_2 = 0 ; for ( int var_3 = 0 ; var_3 < var_0 . length ; var_3 ++ ) { if ( var_0 [ var_3 ] == 1 ) { var_1 ++ ; } else var_2 ++ ; } if ( var_1 == 0 ) return 0 ; int var_4 = var_1 ; var_1 = 0 ; var_2 = 0 ; int var_3 = 0 , var_5 = var_4 - 1 ; for ( int var_6 = var_3 ; var_6 <= var_5 ; var_6 ++ ) { if ( var_0 [ var_6 ] == 1 ) { var_1 ++ ; } else var_2 ++ ; } var_3 ++ ; var_5 ++ ; int min = var_2 ; for ( ; var_5 < var_0 . length ; var_3 ++ , var_5 ++ ) { if ( var_0 [ var_5 ] == 0 ) { var_2 ++ ; } else var_1 ++ ; if ( var_0 [ var_3 - 1 ] == 0 ) { var_2 -- ; } else var_1 -- ; min = Math . min ( min , var_2 ) ; } return min ; }
2
0<SEP>1
1,137
<gouthampradhan>array_HIndex_1.java
public int hIndex(int[] citations) { int n = citations.length; int[] count = new int[n + 1]; int[] S = new int[n + 1]; for (int i = 0; i < citations.length; i++) { if (citations[i] > n) { citations[i] = n; } } for (int citation : citations) { count[citation]++; } S[n] = count[n]; for (int i = n - 1; i >= 0; i--) { S[i] = count[i] + S[i + 1]; } for (int i = n; i >= 0; i--) { if (i <= S[i]) { return i; } } return 0; }
public int sample_funcname ( int [ ] var_0 ) { int var_1 = var_0 . length ; int [ ] var_2 = new int [ var_1 + 1 ] ; int [ ] var_3 = new int [ var_1 + 1 ] ; for ( int var_4 = 0 ; var_4 < var_0 . length ; var_4 ++ ) { if ( var_0 [ var_4 ] > var_1 ) { var_0 [ var_4 ] = var_1 ; } } for ( int var_5 : var_0 ) { var_2 [ var_5 ] ++ ; } var_3 [ var_1 ] = var_2 [ var_1 ] ; for ( int var_4 = var_1 - 1 ; var_4 >= 0 ; var_4 -- ) { var_3 [ var_4 ] = var_2 [ var_4 ] + var_3 [ var_4 + 1 ] ; } for ( int var_4 = var_1 ; var_4 >= 0 ; var_4 -- ) { if ( var_4 <= var_3 [ var_4 ] ) { return var_4 ; } } return 0 ; }
2
1<SEP>0
1,138
<gouthampradhan>math_WaterAndJugProblem_1.java
public boolean canMeasureWater(int x, int y, int z) { if (x == y && y == z) return true; if (z > (x + y)) return false; BigInteger b1 = new BigInteger(String.valueOf(x)); BigInteger b2 = new BigInteger(String.valueOf(y)); BigInteger b3 = b1.gcd(b2); return b3.intValue() != 0 && (z % b3.intValue()) == 0; }
public boolean var_0 ( int var_1 , int var_2 , int var_3 ) { if ( var_1 == var_2 && var_2 == var_3 ) return true ; if ( var_3 > ( var_1 + var_2 ) ) return false ; BigInteger var_4 = new BigInteger ( String . valueOf ( var_1 ) ) ; BigInteger var_5 = new BigInteger ( String . valueOf ( var_2 ) ) ; BigInteger var_6 = var_4 . gcd ( var_5 ) ; return var_6 . intValue ( ) != 0 && ( var_3 % var_6 . intValue ( ) ) == 0 ; }
1
0
1,139
<gouthampradhan>array_ThirdMaximumNumber_1.java
public int thirdMax(int[] nums) { long[] max = {Long.MIN_VALUE, Long.MIN_VALUE, Long.MIN_VALUE}; int count = 0; for (int num : nums) { for (int j = 0; j < 3; j++) { if (max[j] > num) continue; else if (max[j] == num) break; int k = j; long temp1, temp2; temp1 = num; count++; while (k < 3) { temp2 = max[k]; max[k] = temp1; temp1 = temp2; k++; } break; } } System.out.println(Integer.MIN_VALUE); return (count >= 3) ? (int) max[2] : (int) max[0]; }
public int sample_funcname ( int [ ] var_0 ) { long [ ] var_1 = { Long . MIN_VALUE , Long . MIN_VALUE , Long . MIN_VALUE }; int var_2 = 0 ; for ( int var_3 : var_0 ) { for ( int var_4 = 0 ; var_4 < 3 ; var_4 ++ ) { if ( var_1 [ var_4 ] > var_3 ) continue ; else if ( var_1 [ var_4 ] == var_3 ) break ; int var_5 = var_4 ; long var_6 , var_7 ; var_6 = var_3 ; var_2 ++ ; while ( var_5 < 3 ) { var_7 = var_1 [ var_5 ] ; var_1 [ var_5 ] = var_6 ; var_6 = var_7 ; var_5 ++ ; } break ; } } System . out . println ( Integer . MIN_VALUE ) ; return ( var_2 >= 3 ) ? ( int ) var_1 [ 2 ] : ( int ) var_1 [ 0 ] ; }
3
0<SEP>3<SEP>2
1,140
<gouthampradhan>math_Base7_1.java
public String convertToBase7(int num) { Integer.toString(7, 7); if (num == 0) return "0"; int q = Math.abs(num), r; StringBuilder sb = new StringBuilder(); while (q != 0) { r = q % 7; sb.append(r); q /= 7; } if (num < 0) { return "-" + sb.reverse().toString(); } else return sb.reverse().toString(); }
public String var_0 ( int var_1 ) { Integer . toString ( 7 , 7 ) ; if ( var_1 == 0 ) return "0" ; int var_2 = Math . abs ( var_1 ) , var_3 ; StringBuilder var_4 = new StringBuilder ( ) ; while ( var_2 != 0 ) { var_3 = var_2 % 7 ; var_4 . append ( var_3 ) ; var_2 /= 7 ; } if ( var_1 < 0 ) { return "-" + var_4 . reverse ( ) . toString ( ) ; } else return var_4 . reverse ( ) . toString ( ) ; }
4
<D_QUOTE>0<D_QUOTE><SEP>7<SEP>0<SEP><D_QUOTE>-<D_QUOTE>
1,142
<gouthampradhan>bit_manipulation_BinaryNumberWithAlternatingBits_1.java
public boolean hasAlternatingBits(int n) { int curr = n & 1; int pos = 0; for (int i = 0; i < 32; i++) { if ((n & (1 << i)) > 0) { pos = i; } } for (int i = 1; i <= pos; i++) { int temp = (1 << i) & n; if ((temp > 0 && curr > 0) || (temp == 0 && curr == 0)) return false; curr = temp; } return true; }
public boolean var_0 ( int var_1 ) { int var_2 = var_1 & 1 ; int var_3 = 0 ; for ( int var_4 = 0 ; var_4 < 32 ; var_4 ++ ) { if ( ( var_1 & ( 1 << var_4 ) ) > 0 ) { var_3 = var_4 ; } } for ( int var_4 = 1 ; var_4 <= var_3 ; var_4 ++ ) { int var_5 = ( 1 << var_4 ) & var_1 ; if ( ( var_5 > 0 && var_2 > 0 ) || ( var_5 == 0 && var_2 == 0 ) ) return false ; var_2 = var_5 ; } return true ; }
3
1<SEP>0<SEP>32
1,143
<gouthampradhan>dynamic_programming_OnesAndZeroes_1.java
public int findMaxForm(String[] strs, int m, int n) { int[][][] dp = new int[strs.length + 1][m + 1][n + 1]; for (int i = strs.length - 1; i >= 0; i--) { String string = strs[i]; int zero = 0; int one = 0; for (char c : string.toCharArray()) { if (c == '0') { zero++; } else { one++; } } for (int p = m; p >= 0; p--) { for (int q = n; q >= 0; q--) { dp[i][p][q] = dp[i + 1][p][q]; if (p - zero >= 0 && q - one >= 0) { dp[i][p][q] = Math.max(dp[i][p][q], dp[i + 1][p - zero][q - one] + 1); } } } } return dp[0][m][n]; }
public int sample_funcname ( String [ ] var_0 , int var_1 , int var_2 ) { int [ ] [ ] [ ] var_3 = new int [ var_0 . length + 1 ] [ var_1 + 1 ] [ var_2 + 1 ] ; for ( int var_4 = var_0 . length - 1 ; var_4 >= 0 ; var_4 -- ) { String var_5 = var_0 [ var_4 ] ; int var_6 = 0 ; int var_7 = 0 ; for ( char var_8 : var_5 . toCharArray ( ) ) { if ( var_8 == '0' ) { var_6 ++ ; } else { var_7 ++ ; } } for ( int var_9 = var_1 ; var_9 >= 0 ; var_9 -- ) { for ( int var_10 = var_2 ; var_10 >= 0 ; var_10 -- ) { var_3 [ var_4 ] [ var_9 ] [ var_10 ] = var_3 [ var_4 + 1 ] [ var_9 ] [ var_10 ] ; if ( var_9 - var_6 >= 0 && var_10 - var_7 >= 0 ) { var_3 [ var_4 ] [ var_9 ] [ var_10 ] = Math . max ( var_3 [ var_4 ] [ var_9 ] [ var_10 ] , var_3 [ var_4 + 1 ] [ var_9 - var_6 ] [ var_10 - var_7 ] + 1 ) ; } } } } return var_3 [ 0 ] [ var_1 ] [ var_2 ] ; }
3
1<SEP>0<SEP><S_QUOTE>0<S_QUOTE>
1,144
<gouthampradhan>dynamic_programming_InterleavingString_1.java
public boolean isInterleave(String s1, String s2, String s3) { boolean[][] DP = new boolean[s1.length() + 1][s2.length() + 1]; DP[0][0] = true; if (s3.length() != (s2.length() + s1.length())) return false; for (int i = 0; i <= s1.length(); i++) { for (int j = 0; j <= s2.length(); j++) { if (i == 0 && j == 0) continue; int index = (i + j); if (j > 0) { if (s3.charAt(index - 1) == s2.charAt(j - 1) && DP[i][j - 1]) { DP[i][j] = true; } } if (i > 0) { if (s3.charAt(index - 1) == s1.charAt(i - 1) && DP[i - 1][j]) { DP[i][j] = true; } } } } return DP[s1.length()][s2.length()]; }
public boolean var_0 ( String var_1 , String var_2 , String var_3 ) { boolean [ ] [ ] var_4 = new boolean [ var_1 . length ( ) + 1 ] [ var_2 . length ( ) + 1 ] ; var_4 [ 0 ] [ 0 ] = true ; if ( var_3 . length ( ) != ( var_2 . length ( ) + var_1 . length ( ) ) ) return false ; for ( int var_5 = 0 ; var_5 <= var_1 . length ( ) ; var_5 ++ ) { for ( int var_6 = 0 ; var_6 <= var_2 . length ( ) ; var_6 ++ ) { if ( var_5 == 0 && var_6 == 0 ) continue ; int var_7 = ( var_5 + var_6 ) ; if ( var_6 > 0 ) { if ( var_3 . charAt ( var_7 - 1 ) == var_2 . charAt ( var_6 - 1 ) && var_4 [ var_5 ] [ var_6 - 1 ] ) { var_4 [ var_5 ] [ var_6 ] = true ; } } if ( var_5 > 0 ) { if ( var_3 . charAt ( var_7 - 1 ) == var_1 . charAt ( var_5 - 1 ) && var_4 [ var_5 - 1 ] [ var_6 ] ) { var_4 [ var_5 ] [ var_6 ] = true ; } } } } return var_4 [ var_1 . length ( ) ] [ var_2 . length ( ) ] ; }
2
1<SEP>0
1,145
<gouthampradhan>array_SparseMatrixMultiplication_1.java
public int[][] multiply(int[][] A, int[][] B) { boolean[] AH = new boolean[A.length]; boolean[] BH = new boolean[B[0].length]; for (int i = 0; i < A.length; i++) { for (int j = 0; j < A[0].length; j++) { if (A[i][j] != 0) { AH[i] = true; break; } } } for (int i = 0; i < B[0].length; i++) { for (int j = 0; j < B.length; j++) { if (B[j][i] != 0) { BH[i] = true; break; } } } int[][] C = new int[A.length][B[0].length]; for (int i = 0; i < C.length; i++) { if (AH[i]) { for (int j = 0; j < C[0].length; j++) { if (BH[j]) { int sum = 0; for (int k = 0; k < A[0].length; k++) { sum += A[i][k] * B[k][j]; } C[i][j] = sum; } } } } return C; }
public int [ ] [ ] sample_funcname ( int [ ] [ ] var_0 , int [ ] [ ] var_1 ) { boolean [ ] var_2 = new boolean [ var_0 . length ] ; boolean [ ] var_3 = new boolean [ var_1 [ 0 ] . length ] ; for ( int var_4 = 0 ; var_4 < var_0 . length ; var_4 ++ ) { for ( int var_5 = 0 ; var_5 < var_0 [ 0 ] . length ; var_5 ++ ) { if ( var_0 [ var_4 ] [ var_5 ] != 0 ) { var_2 [ var_4 ] = true ; break ; } } } for ( int var_4 = 0 ; var_4 < var_1 [ 0 ] . length ; var_4 ++ ) { for ( int var_5 = 0 ; var_5 < var_1 . length ; var_5 ++ ) { if ( var_1 [ var_5 ] [ var_4 ] != 0 ) { var_3 [ var_4 ] = true ; break ; } } } int [ ] [ ] var_6 = new int [ var_0 . length ] [ var_1 [ 0 ] . length ] ; for ( int var_4 = 0 ; var_4 < var_6 . length ; var_4 ++ ) { if ( var_2 [ var_4 ] ) { for ( int var_5 = 0 ; var_5 < var_6 [ 0 ] . length ; var_5 ++ ) { if ( var_3 [ var_5 ] ) { int var_7 = 0 ; for ( int var_8 = 0 ; var_8 < var_0 [ 0 ] . length ; var_8 ++ ) { var_7 += var_0 [ var_4 ] [ var_8 ] * var_1 [ var_8 ] [ var_5 ] ; } var_6 [ var_4 ] [ var_5 ] = var_7 ; } } } } return var_6 ; }
1
0
1,146
<gouthampradhan>math_MinimumIndexSumOfTwoLists_1.java
public String[] findRestaurant(String[] list1, String[] list2) { Map<String, Integer> index = new HashMap<>(); for (int i = 0; i < list2.length; i++) { String s = list2[i]; index.put(s, i); } int min = Integer.MAX_VALUE; List<String> list = new ArrayList<>(); for (int i = 0; i < list1.length; i++) { if (index.containsKey(list1[i])) { if (i + index.get(list1[i]) <= min) { min = i + index.get(list1[i]); } } } for (int i = 0; i < list1.length; i++) { if (index.containsKey(list1[i])) { if (i + index.get(list1[i]) == min) { list.add(list1[i]); } } } String[] ans = new String[list.size()]; int i = 0; for (String s : list) { ans[i++] = s; } return ans; }
public String [ ] var_0 ( String [ ] var_1 , String [ ] var_2 ) { Map < String , Integer > var_3 = new HashMap < > ( ) ; for ( int var_4 = 0 ; var_4 < var_2 . length ; var_4 ++ ) { String var_5 = var_2 [ var_4 ] ; var_3 . put ( var_5 , var_4 ) ; } int var_6 = Integer . MAX_VALUE ; List < String > var_7 = new ArrayList < > ( ) ; for ( int var_4 = 0 ; var_4 < var_1 . length ; var_4 ++ ) { if ( var_3 . containsKey ( var_1 [ var_4 ] ) ) { if ( var_4 + var_3 . get ( var_1 [ var_4 ] ) <= var_6 ) { var_6 = var_4 + var_3 . get ( var_1 [ var_4 ] ) ; } } } for ( int var_4 = 0 ; var_4 < var_1 . length ; var_4 ++ ) { if ( var_3 . containsKey ( var_1 [ var_4 ] ) ) { if ( var_4 + var_3 . get ( var_1 [ var_4 ] ) == var_6 ) { var_7 . add ( var_1 [ var_4 ] ) ; } } } String [ ] var_8 = new String [ var_7 . size ( ) ] ; int var_4 = 0 ; for ( String var_5 : var_7 ) { var_8 [ var_4 ++ ] = var_5 ; } return var_8 ; }
1
0
1,147
<gouthampradhan>string_ValidPalindrome_1.java
public boolean isPalindrome(String s) { if (s == null || s.isEmpty()) return true; s = s.toLowerCase(); for (int i = 0, j = s.length() - 1; i < j; ) { char f = s.charAt(i); char l = s.charAt(j); if (!(f >= 'a' && f <= 'z') && !(f >= '0' && f <= '9')) { i++; continue; } if (!(l >= 'a' && l <= 'z') && !(l >= '0' && l <= '9')) { j--; continue; } if (f != l) return false; i++; j--; } return true; }
public boolean var_0 ( String var_1 ) { if ( var_1 == null || var_1 . isEmpty ( ) ) return true ; var_1 = var_1 . toLowerCase ( ) ; for ( int var_2 = 0 , var_3 = var_1 . length ( ) - 1 ; var_2 < var_3 ; ) { char var_4 = var_1 . charAt ( var_2 ) ; char var_5 = var_1 . charAt ( var_3 ) ; if ( ! ( var_4 >= 'a' && var_4 <= 'z' ) && ! ( var_4 >= '0' && var_4 <= '9' ) ) { var_2 ++ ; continue ; } if ( ! ( var_5 >= 'a' && var_5 <= 'z' ) && ! ( var_5 >= '0' && var_5 <= '9' ) ) { var_3 -- ; continue ; } if ( var_4 != var_5 ) return false ; var_2 ++ ; var_3 -- ; } return true ; }
6
<S_QUOTE>9<S_QUOTE><SEP>0<SEP>1<SEP><S_QUOTE>z<S_QUOTE><SEP><S_QUOTE>0<S_QUOTE><SEP><S_QUOTE>a<S_QUOTE>
1,148
<gouthampradhan>dynamic_programming_StoneGameIV_1.java
private int dp(int n, int p, int[] perfectSquares, int[] DP) { if (n == 0) return 1; else if (DP[n] != 0) return DP[n]; else { int result = 1; for (int sq : perfectSquares) { if (n < sq) break; int r = dp(n - sq, ((p + 1) % 2), perfectSquares, DP); if (r == 1) { result = 2; break; } } DP[n] = result; return result; } }
private int sample_funcname ( int n , int p , int [ ] perfectSquares , int [ ] DP ) { if ( n == 0 ) return 1 ; else if ( DP [ n ] != 0 ) return DP [ n ] ; else { int result = 1 ; for ( int sq : perfectSquares ) { if ( n < sq ) break ; int r = dp ( n - sq , ( ( p + 1 ) % 2 ) , perfectSquares , DP ) ; if ( r == 1 ) { result = 2 ; break ; } } DP [ n ] = result ; return result ; } }
3
2<SEP>0<SEP>1
1,149
<gouthampradhan>string_LongestWordInDictonary_1.java
public String findLongestWord(String s, List<String> d) { Collections.sort( d, Comparator.comparing(String::length).reversed().thenComparing(String::compareTo)); for (String str : d) { if (str.length() <= s.length()) { int i = 0, j = 0; for (int l1 = s.length(), l2 = str.length(); i < l1 && j < l2; ) { if (s.charAt(i) == str.charAt(j)) { i++; j++; } else { i++; } } if (j >= str.length()) return str; } } return ""; }
public String var_0 ( String var_1 , List < String > var_2 ) { Collections . sort ( var_2 , Comparator . comparing ( String :: length ) . reversed ( ) . thenComparing ( String :: compareTo ) ) ; for ( String var_3 : var_2 ) { if ( var_3 . length ( ) <= var_1 . length ( ) ) { int var_4 = 0 , var_5 = 0 ; for ( int var_6 = var_1 . length ( ) , var_7 = var_3 . length ( ) ; var_4 < var_6 && var_5 < var_7 ; ) { if ( var_1 . charAt ( var_4 ) == var_3 . charAt ( var_5 ) ) { var_4 ++ ; var_5 ++ ; } else { var_4 ++ ; } } if ( var_5 >= var_3 . length ( ) ) return var_3 ; } } return "" ; }
2
0<SEP><D_QUOTE><D_QUOTE>
1,150
<gouthampradhan>backtracking_SubsetsII_1.java
public List<List<Integer>> subsetsWithDup(int[] nums) { List<List<Integer>> result = new ArrayList<>(); result.add(new ArrayList<>()); int start = 0, newStart = 0; Arrays.sort(nums); for (int i = 0, l = nums.length; i < l; i++) { newStart = result.size(); if (i == 0 || nums[i] != nums[i - 1]) { start = 0; } for (int j = start, resLen = result.size(); j < resLen; j++) { List<Integer> newList = new ArrayList<>(result.get(j)); newList.add(nums[i]); result.add(newList); } start = newStart; } return result; }
public List < List < Integer >> var_0 ( int [ ] var_1 ) { List < List < Integer >> var_2 = new ArrayList < > ( ) ; var_2 . add ( new ArrayList < > ( ) ) ; int var_3 = 0 , var_4 = 0 ; Arrays . sort ( var_1 ) ; for ( int var_5 = 0 , var_6 = var_1 . length ; var_5 < var_6 ; var_5 ++ ) { var_4 = var_2 . size ( ) ; if ( var_5 == 0 || var_1 [ var_5 ] != var_1 [ var_5 - 1 ] ) { var_3 = 0 ; } for ( int var_7 = var_3 , var_8 = var_2 . size ( ) ; var_7 < var_8 ; var_7 ++ ) { List < Integer > var_9 = new ArrayList < > ( var_2 . get ( var_7 ) ) ; var_9 . add ( var_1 [ var_5 ] ) ; var_2 . add ( var_9 ) ; } var_3 = var_4 ; } return var_2 ; }
2
0<SEP>1
1,151
<gouthampradhan>array_TwoSumII_1.java
public int[] twoSum(int[] numbers, int target) { int i = 0, j = numbers.length - 1; while (i < j) { int x = (numbers[i] + numbers[j]); if (x == target) { int[] result = new int[2]; result[0] = i + 1; result[1] = j + 1; return result; } else if (x < target) i++; else j--; } return new int[2]; }
public int [ ] sample_funcname ( int [ ] var_0 , int var_1 ) { int var_2 = 0 , var_3 = var_0 . length - 1 ; while ( var_2 < var_3 ) { int var_4 = ( var_0 [ var_2 ] + var_0 [ var_3 ] ) ; if ( var_4 == var_1 ) { int [ ] var_5 = new int [ 2 ] ; var_5 [ 0 ] = var_2 + 1 ; var_5 [ 1 ] = var_3 + 1 ; return var_5 ; } else if ( var_4 < var_1 ) var_2 ++ ; else var_3 -- ; } return new int [ 2 ] ; }
3
2<SEP>0<SEP>1
1,152
<gouthampradhan>dynamic_programming_MaximumProductSubarray_1.java
public int maxProduct(int[] nums) { if (nums.length == 1) return nums[0]; int min = nums[0]; int max = nums[0]; int result = max; for (int i = 1; i < nums.length; i++) { int prevMin = min, prevMax = max; min = Math.min(nums[i], Math.min(nums[i] * prevMin, nums[i] * prevMax)); max = Math.max(nums[i], Math.max(nums[i] * prevMin, nums[i] * prevMax)); result = Math.max(result, max); } return result; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 . length == 1 ) return var_0 [ 0 ] ; int min = var_0 [ 0 ] ; int max = var_0 [ 0 ] ; int var_1 = max ; for ( int var_2 = 1 ; var_2 < var_0 . length ; var_2 ++ ) { int var_3 = min , var_4 = max ; min = Math . min ( var_0 [ var_2 ] , Math . min ( var_0 [ var_2 ] * var_3 , var_0 [ var_2 ] * var_4 ) ) ; max = Math . max ( var_0 [ var_2 ] , Math . max ( var_0 [ var_2 ] * var_3 , var_0 [ var_2 ] * var_4 ) ) ; var_1 = Math . max ( var_1 , max ) ; } return var_1 ; }
2
1<SEP>0
1,153
<gouthampradhan>dynamic_programming_BestTimeToBuyAndSellStocks_1.java
public int maxProfit(int[] prices) { if (prices.length == 0) return 0; int[] max = new int[prices.length]; max[prices.length - 1] = prices[prices.length - 1]; for (int i = prices.length - 2; i >= 0; i--) { max[i] = Math.max(prices[i], max[i + 1]); } int result = Integer.MIN_VALUE; for (int i = 0, l = max.length; i < l; i++) { result = Math.max(result, max[i] - prices[i]); } return result; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 . length == 0 ) return 0 ; int [ ] max = new int [ var_0 . length ] ; max [ var_0 . length - 1 ] = var_0 [ var_0 . length - 1 ] ; for ( int var_1 = var_0 . length - 2 ; var_1 >= 0 ; var_1 -- ) { max [ var_1 ] = Math . max ( var_0 [ var_1 ] , max [ var_1 + 1 ] ) ; } int var_2 = Integer . MIN_VALUE ; for ( int var_1 = 0 , var_3 = max . length ; var_1 < var_3 ; var_1 ++ ) { var_2 = Math . max ( var_2 , max [ var_1 ] - var_0 [ var_1 ] ) ; } return var_2 ; }
3
2<SEP>0<SEP>1
1,154
<gouthampradhan>array_FindPivotIndex_1.java
public int pivotIndex(int[] nums) { if (nums.length == 1) return 0; int[] left = new int[nums.length]; int[] right = new int[nums.length]; left[0] = nums[0]; for (int i = 1; i < nums.length; i++) { left[i] = left[i - 1] + nums[i]; } right[nums.length - 1] = nums[nums.length - 1]; for (int i = nums.length - 2; i >= 0; i--) { right[i] = right[i + 1] + nums[i]; } for (int i = 0; i < nums.length; i++) { int l, r; if (i == 0) { l = 0; } else { l = left[i - 1]; } if (i == nums.length - 1) { r = 0; } else { r = right[i + 1]; } if (l == r) return i; } return -1; }
public int sample_funcname ( int [ ] var_0 ) { if ( var_0 . length == 1 ) return 0 ; int [ ] var_1 = new int [ var_0 . length ] ; int [ ] var_2 = new int [ var_0 . length ] ; var_1 [ 0 ] = var_0 [ 0 ] ; for ( int var_3 = 1 ; var_3 < var_0 . length ; var_3 ++ ) { var_1 [ var_3 ] = var_1 [ var_3 - 1 ] + var_0 [ var_3 ] ; } var_2 [ var_0 . length - 1 ] = var_0 [ var_0 . length - 1 ] ; for ( int var_3 = var_0 . length - 2 ; var_3 >= 0 ; var_3 -- ) { var_2 [ var_3 ] = var_2 [ var_3 + 1 ] + var_0 [ var_3 ] ; } for ( int var_3 = 0 ; var_3 < var_0 . length ; var_3 ++ ) { int var_4 , var_5 ; if ( var_3 == 0 ) { var_4 = 0 ; } else { var_4 = var_1 [ var_3 - 1 ] ; } if ( var_3 == var_0 . length - 1 ) { var_5 = 0 ; } else { var_5 = var_2 [ var_3 + 1 ] ; } if ( var_4 == var_5 ) return var_3 ; } return - 1 ; }
3
1<SEP>0<SEP>2
1,155
<gouthampradhan>string_ValidWordSquare_1.java
public boolean validWordSquare(List<String> words) { List<String> newList = new ArrayList<>(); int max = 0; for (int i = 0; i < words.size(); i++) { max = Math.max(max, words.get(i).length()); } for (int i = 0; i < max; i++) { StringBuilder sb = new StringBuilder(); for (String w : words) { if (i < w.length()) { sb.append(w.charAt(i)); } else break; } newList.add(sb.toString()); } if (words.size() != newList.size()) return false; for (int i = 0, l = words.size(); i < l; i++) { if (!words.get(i).equals(newList.get(i))) return false; } return true; }
public boolean var_0 ( List < String > var_1 ) { List < String > var_2 = new ArrayList < > ( ) ; int max = 0 ; for ( int var_3 = 0 ; var_3 < var_1 . size ( ) ; var_3 ++ ) { max = Math . max ( max , var_1 . get ( var_3 ) . length ( ) ) ; } for ( int var_3 = 0 ; var_3 < max ; var_3 ++ ) { StringBuilder var_4 = new StringBuilder ( ) ; for ( String var_5 : var_1 ) { if ( var_3 < var_5 . length ( ) ) { var_4 . append ( var_5 . charAt ( var_3 ) ) ; } else break ; } var_2 . add ( var_4 . toString ( ) ) ; } if ( var_1 . size ( ) != var_2 . size ( ) ) return false ; for ( int var_3 = 0 , var_6 = var_1 . size ( ) ; var_3 < var_6 ; var_3 ++ ) { if ( ! var_1 . get ( var_3 ) . equals ( var_2 . get ( var_3 ) ) ) return false ; } return true ; }
1
0
1,156
<gouthampradhan>dynamic_programming_WordBreak_1.java
private boolean dp(int i, String s, Map<Integer, Boolean> dic, Set<String> dictionary) { if (i == s.length()) return true; else if (dic.containsKey(i)) return dic.get(i); else { for (int j = i, l = s.length(); j < l; j++) { String subStr = s.substring(i, j + 1); if (dictionary.contains(subStr)) { if (dp(j + 1, s, dic, dictionary)) { dic.put(i, true); break; } } } } if (!dic.containsKey(i)) dic.put(i, false); return dic.get(i); }
private boolean sample_funcname ( int i , String s , Map < Integer , Boolean > dic , Set < String > dictionary ) { if ( i == s . length ( ) ) return true ; else if ( dic . containsKey ( i ) ) return dic . get ( i ) ; else { for ( int j = i , l = s . length ( ) ; j < l ; j ++ ) { String subStr = s . substring ( i , j + 1 ) ; if ( dictionary . contains ( subStr ) ) { if ( dp ( j + 1 , s , dic , dictionary ) ) { dic . put ( i , true ) ; break ; } } } } if ( ! dic . containsKey ( i ) ) dic . put ( i , false ) ; return dic . get ( i ) ; }
1
1
1,157
<gouthampradhan>hashing_LargestUniqueNumber_1.java
public int largestUniqueNumber(int[] A) { Map<Integer, Integer> map = new HashMap<>(); for (int i : A) { map.putIfAbsent(i, 0); int v = map.get(i) + 1; map.put(i, v); } int max = -1; for (int k : map.keySet()) { if (map.get(k) == 1) { max = Math.max(max, k); } } return max; }
public int sample_funcname ( int [ ] var_0 ) { Map < Integer , Integer > var_1 = new HashMap < > ( ) ; for ( int var_2 : var_0 ) { var_1 . putIfAbsent ( var_2 , 0 ) ; int var_3 = var_1 . get ( var_2 ) + 1 ; var_1 . put ( var_2 , var_3 ) ; } int max = - 1 ; for ( int var_4 : var_1 . keySet ( ) ) { if ( var_1 . get ( var_4 ) == 1 ) { max = Math . max ( max , var_4 ) ; } } return max ; }
2
0<SEP>1
1,159
<gouthampradhan>greedy_MinimumTimeToBuildBlocks_1.java
public int minBuildTime(int[] blocks, int split) { PriorityQueue<Integer> queue = new PriorityQueue<>(); for (int b : blocks) queue.offer(b); while (queue.size() != 1) { int a = queue.poll(); int b = queue.poll(); queue.offer(Math.max(a, b) + split); } return queue.poll(); }
public int sample_funcname ( int [ ] var_0 , int var_1 ) { PriorityQueue < Integer > var_2 = new PriorityQueue < > ( ) ; for ( int var_3 : var_0 ) var_2 . offer ( var_3 ) ; while ( var_2 . size ( ) != 1 ) { int var_4 = var_2 . poll ( ) ; int var_3 = var_2 . poll ( ) ; var_2 . offer ( Math . max ( var_4 , var_3 ) + var_1 ) ; } return var_2 . poll ( ) ; }
1
1
1,161
<gouthampradhan>bit_manipulation_TotalHammingDistance_1.java
public int totalHammingDistance(int[] nums) { int sum = 0; for (int i = 0; i < 32; i++) { int numOfOnes = 0; int p = (1 << i); for (int num : nums) { if ((num & p) > 0) { numOfOnes++; } } sum += ((nums.length - numOfOnes) * numOfOnes); } return sum; }
public int sample_funcname ( int [ ] var_0 ) { int var_1 = 0 ; for ( int var_2 = 0 ; var_2 < 32 ; var_2 ++ ) { int var_3 = 0 ; int var_4 = ( 1 << var_2 ) ; for ( int var_5 : var_0 ) { if ( ( var_5 & var_4 ) > 0 ) { var_3 ++ ; } } var_1 += ( ( var_0 . length - var_3 ) * var_3 ) ; } return var_1 ; }
3
0<SEP>32<SEP>1
1,162
<gouthampradhan>greedy_MaximumLengthOfPairChain_1.java
public int findLongestChain(int[][] pairs) { Arrays.sort( pairs, (o1, o2) -> o1[1] == o2[1] ? Integer.compare(o1[0], o2[0]) : Integer.compare(o1[1], o2[1])); int count = 1; int[] curr = pairs[0]; for (int i = 1; i < pairs.length; i++) { if (pairs[i][0] > curr[1]) { count++; curr = pairs[i]; } } return count; }
public int sample_funcname ( int [ ] [ ] var_0 ) { Arrays . sort ( var_0 , ( var_1 , var_2 ) -> var_1 [ 1 ] == var_2 [ 1 ] ? Integer . compare ( var_1 [ 0 ] , var_2 [ 0 ] ) : Integer . compare ( var_1 [ 1 ] , var_2 [ 1 ] ) ) ; int var_3 = 1 ; int [ ] var_4 = var_0 [ 0 ] ; for ( int var_5 = 1 ; var_5 < var_0 . length ; var_5 ++ ) { if ( var_0 [ var_5 ] [ 0 ] > var_4 [ 1 ] ) { var_3 ++ ; var_4 = var_0 [ var_5 ] ; } } return var_3 ; }
2
1<SEP>0
1,163
<gouthampradhan>string_StudentAttendanceRecordI_1.java
public boolean checkRecord(String s) { int count = 0; for (int c : s.toCharArray()) { if (c == 'A') { count++; } if (count > 1) return false; } if (s.contains("LLL")) return false; return true; }
public boolean var_0 ( String var_1 ) { int var_2 = 0 ; for ( int var_3 : var_1 . toCharArray ( ) ) { if ( var_3 == 'A' ) { var_2 ++ ; } if ( var_2 > 1 ) return false ; } if ( var_1 . contains ( "LLL" ) ) return false ; return true ; }
4
<D_QUOTE>LLL<D_QUOTE><SEP>0<SEP>1<SEP><S_QUOTE>A<S_QUOTE>
1,164
<gouthampradhan>dynamic_programming_MakeArrayStrictlyIncreasing_1.java
private int binarySearch(int[] A, int k) { int l = 0, h = A.length; int ans = -1; while (l < h) { int m = l + (h - l) / 2; if (A[m] > k) { ans = m; h = m; } else l = m + 1; } return ans; }
private int sample_funcname ( int [ ] var_0 , int var_1 ) { int var_2 = 0 , var_3 = var_0 . length ; int var_4 = - 1 ; while ( var_2 < var_3 ) { int var_5 = var_2 + ( var_3 - var_2 ) / 2 ; if ( var_0 [ var_5 ] > var_1 ) { var_4 = var_5 ; var_3 = var_5 ; } else var_2 = var_5 + 1 ; } return var_4 ; }
3
2<SEP>0<SEP>1
1,165
<gouthampradhan>math_RectangleOverlap_1.java
public boolean isRectangleOverlap(int[] rec1, int[] rec2) { boolean x = ((rec1[0] >= rec2[0] && rec1[0] < rec2[2]) || (rec2[0] >= rec1[0] && rec2[0] < rec1[2])); boolean y = ((rec1[1] >= rec2[1] && rec1[1] < rec2[3]) || (rec2[1] >= rec1[1] && rec2[1] < rec1[3])); return x && y; }
public boolean var_0 ( int [ ] var_1 , int [ ] var_2 ) { boolean var_3 = ( ( var_1 [ 0 ] >= var_2 [ 0 ] && var_1 [ 0 ] < var_2 [ 2 ] ) || ( var_2 [ 0 ] >= var_1 [ 0 ] && var_2 [ 0 ] < var_1 [ 2 ] ) ) ; boolean var_4 = ( ( var_1 [ 1 ] >= var_2 [ 1 ] && var_1 [ 1 ] < var_2 [ 3 ] ) || ( var_2 [ 1 ] >= var_1 [ 1 ] && var_2 [ 1 ] < var_1 [ 3 ] ) ) ; return var_3 && var_4 ; }
4
0<SEP>3<SEP>1<SEP>2
1,166
<gouthampradhan>string_AddBinary_1.java
private String calculate(String a, String b) { int carry = 0; int d = a.length() - b.length(); StringBuilder sb = new StringBuilder(); for (int i = a.length() - 1; i >= 0; i--) { int first = Integer.parseInt(String.valueOf(a.charAt(i))); int second = i - d >= 0 ? Integer.parseInt(String.valueOf(b.charAt(i - d))) : 0; int sum = (first + second + carry); carry = sum / 2; sb.append(sum % 2); } if (carry != 0) sb.append(carry); return sb.reverse().toString(); }
private String var_0 ( String var_1 , String var_2 ) { int var_3 = 0 ; int var_4 = var_1 . length ( ) - var_2 . length ( ) ; StringBuilder var_5 = new StringBuilder ( ) ; for ( int var_6 = var_1 . length ( ) - 1 ; var_6 >= 0 ; var_6 -- ) { int var_7 = Integer . parseInt ( String . valueOf ( var_1 . charAt ( var_6 ) ) ) ; int var_8 = var_6 - var_4 >= 0 ? Integer . parseInt ( String . valueOf ( var_2 . charAt ( var_6 - var_4 ) ) ) : 0 ; int var_9 = ( var_7 + var_8 + var_3 ) ; var_3 = var_9 / 2 ; var_5 . append ( var_9 % 2 ) ; } if ( var_3 != 0 ) var_5 . append ( var_3 ) ; return var_5 . reverse ( ) . toString ( ) ; }
3
2<SEP>0<SEP>1
1,167
<gouthampradhan>dynamic_programming_MaximumVacationDays_1.java
public int maxVacationDays(int[][] flights, int[][] days) { int N = days.length; int W = days[0].length; int[][] DP = new int[N][W + 1]; for (int w = W - 1; w >= 0; w--) { for (int n = 0; n < N; n++) { DP[n][w] = days[n][w] + DP[n][w + 1]; } for (int n = 0; n < N; n++) { int max = Integer.MIN_VALUE; int[] F = flights[n]; for (int i = 0; i < F.length; i++) { if (F[i] == 1) { max = Math.max(max, days[i][w] + DP[i][w + 1]); } } DP[n][w] = Math.max(DP[n][w], max); } } return DP[0][0]; }
public int sample_funcname ( int [ ] [ ] var_0 , int [ ] [ ] var_1 ) { int var_2 = var_1 . length ; int var_3 = var_1 [ 0 ] . length ; int [ ] [ ] var_4 = new int [ var_2 ] [ var_3 + 1 ] ; for ( int var_5 = var_3 - 1 ; var_5 >= 0 ; var_5 -- ) { for ( int var_6 = 0 ; var_6 < var_2 ; var_6 ++ ) { var_4 [ var_6 ] [ var_5 ] = var_1 [ var_6 ] [ var_5 ] + var_4 [ var_6 ] [ var_5 + 1 ] ; } for ( int var_6 = 0 ; var_6 < var_2 ; var_6 ++ ) { int max = Integer . MIN_VALUE ; int [ ] var_7 = var_0 [ var_6 ] ; for ( int var_8 = 0 ; var_8 < var_7 . length ; var_8 ++ ) { if ( var_7 [ var_8 ] == 1 ) { max = Math . max ( max , var_1 [ var_8 ] [ var_5 ] + var_4 [ var_8 ] [ var_5 + 1 ] ) ; } } var_4 [ var_6 ] [ var_5 ] = Math . max ( var_4 [ var_6 ] [ var_5 ] , max ) ; } } return var_4 [ 0 ] [ 0 ] ; }
2
0<SEP>1
1,168
<gouthampradhan>dynamic_programming_MaximalSquare_1.java
public int maximalSquare(char[][] matrix) { if (matrix.length == 0) return 0; int[][] dp = new int[matrix.length][matrix[0].length]; for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[0].length; j++) { if (j - 1 >= 0 && i - 1 >= 0) { if (matrix[i][j] == '1') { dp[i][j] = Math.min(dp[i - 1][j], dp[i][j - 1]); dp[i][j] = Math.min(dp[i][j], dp[i - 1][j - 1]) + 1; } } else { dp[i][j] = matrix[i][j] == '1' ? 1 : 0; } } } int max = 0; for (int i = 0; i < dp.length; i++) { for (int j = 0; j < dp[0].length; j++) { max = Math.max(max, dp[i][j]); } } return max * max; }
public int sample_funcname ( char [ ] [ ] var_0 ) { if ( var_0 . length == 0 ) return 0 ; int [ ] [ ] var_1 = new int [ var_0 . length ] [ var_0 [ 0 ] . length ] ; for ( int var_2 = 0 ; var_2 < var_0 . length ; var_2 ++ ) { for ( int var_3 = 0 ; var_3 < var_0 [ 0 ] . length ; var_3 ++ ) { if ( var_3 - 1 >= 0 && var_2 - 1 >= 0 ) { if ( var_0 [ var_2 ] [ var_3 ] == '1' ) { var_1 [ var_2 ] [ var_3 ] = Math . min ( var_1 [ var_2 - 1 ] [ var_3 ] , var_1 [ var_2 ] [ var_3 - 1 ] ) ; var_1 [ var_2 ] [ var_3 ] = Math . min ( var_1 [ var_2 ] [ var_3 ] , var_1 [ var_2 - 1 ] [ var_3 - 1 ] ) + 1 ; } } else { var_1 [ var_2 ] [ var_3 ] = var_0 [ var_2 ] [ var_3 ] == '1' ? 1 : 0 ; } } } int max = 0 ; for ( int var_2 = 0 ; var_2 < var_1 . length ; var_2 ++ ) { for ( int var_3 = 0 ; var_3 < var_1 [ 0 ] . length ; var_3 ++ ) { max = Math . max ( max , var_1 [ var_2 ] [ var_3 ] ) ; } } return max * max ; }
3
0<SEP><S_QUOTE>1<S_QUOTE><SEP>1
1,169
<gouthampradhan>string_CompareVersionNumbers_1.java
public int compareVersion(String version1, String version2) { StringTokenizer st1 = new StringTokenizer(version1, "."); StringTokenizer st2 = new StringTokenizer(version2, "."); while (st1.hasMoreTokens() & st2.hasMoreTokens()) { int token1 = Integer.parseInt(st1.nextToken()); int token2 = Integer.parseInt(st2.nextToken()); if (token1 > token2) return 1; else if (token2 > token1) return -1; } if (st1.countTokens() > st2.countTokens()) { while (st1.hasMoreTokens()) { if (Integer.parseInt(st1.nextToken()) > 0) return 1; } } else if (st2.countTokens() > st1.countTokens()) { while (st2.hasMoreTokens()) { if (Integer.parseInt(st2.nextToken()) > 0) return -1; } } return 0; }
public int sample_funcname ( String var_0 , String var_1 ) { StringTokenizer var_2 = new StringTokenizer ( var_0 , "." ) ; StringTokenizer var_3 = new StringTokenizer ( var_1 , "." ) ; while ( var_2 . hasMoreTokens ( ) & var_3 . hasMoreTokens ( ) ) { int var_4 = Integer . parseInt ( var_2 . nextToken ( ) ) ; int var_5 = Integer . parseInt ( var_3 . nextToken ( ) ) ; if ( var_4 > var_5 ) return 1 ; else if ( var_5 > var_4 ) return - 1 ; } if ( var_2 . countTokens ( ) > var_3 . countTokens ( ) ) { while ( var_2 . hasMoreTokens ( ) ) { if ( Integer . parseInt ( var_2 . nextToken ( ) ) > 0 ) return 1 ; } } else if ( var_3 . countTokens ( ) > var_2 . countTokens ( ) ) { while ( var_3 . hasMoreTokens ( ) ) { if ( Integer . parseInt ( var_3 . nextToken ( ) ) > 0 ) return - 1 ; } } return 0 ; }
3
<D_QUOTE>.<D_QUOTE><SEP>1<SEP>0
1,170
<gouthampradhan>stack_MaximalRectangle_1.java
private int getMaxRectangle(int[] heights) { int maxArea = Integer.MIN_VALUE; Stack<Integer> stack = new Stack<>(); int i = 0; for (; i < heights.length; i++) { while (!stack.isEmpty() && heights[stack.peek()] >= heights[i]) { int top = stack.pop(); int base = stack.isEmpty() ? i : i - stack.peek() - 1; maxArea = Math.max(maxArea, base * heights[top]); } stack.push(i); } while (!stack.isEmpty()) { int top = stack.pop(); int base = stack.isEmpty() ? i : i - stack.peek() - 1; maxArea = Math.max(maxArea, base * heights[top]); } return maxArea; }
private int sample_funcname ( int [ ] var_0 ) { int var_1 = Integer . MIN_VALUE ; Stack < Integer > var_2 = new Stack < > ( ) ; int var_3 = 0 ; for ( ; var_3 < var_0 . length ; var_3 ++ ) { while ( ! var_2 . isEmpty ( ) && var_0 [ var_2 . peek ( ) ] >= var_0 [ var_3 ] ) { int var_4 = var_2 . pop ( ) ; int var_5 = var_2 . isEmpty ( ) ? var_3 : var_3 - var_2 . peek ( ) - 1 ; var_1 = Math . max ( var_1 , var_5 * var_0 [ var_4 ] ) ; } var_2 . push ( var_3 ) ; } while ( ! var_2 . isEmpty ( ) ) { int var_4 = var_2 . pop ( ) ; int var_5 = var_2 . isEmpty ( ) ? var_3 : var_3 - var_2 . peek ( ) - 1 ; var_1 = Math . max ( var_1 , var_5 * var_0 [ var_4 ] ) ; } return var_1 ; }
2
0<SEP>1