{ "eval": {}, "predictions": [ { "source": "Write a Java function `public static double calculateAverageBalance(List closingBalances)` to solve the following problem:\nCalculate the average account balance based on the closing balances from the past twelve months.\n\n@param closingBalances A list of closing balances from the past twelve months.\n@return The average account balance.\n\nExample:\ncalculateAverageBalance(Arrays.asList(100.0, 489.12, 12454.12, 1234.10, 823.05, 109.20, 5.27, 1542.25, 839.18, 83.99, 1295.01, 1.75))\nOutput: 1581.42", "ground-truth": null, "prediction": [ "import java.util.List;\n\npublic class AccountBalanceCalculator {\n\n /**\n * Calculates the average account balance based on the closing balances from the past twelve months.\n * \n * @param closingBalances A list of closing balances from the past twelve months.\n * @return The average account balance.\n */\n public static double calculateAverageBalance(List closingBalances) {\n double sum = 0.0;\n for (double balance : closingBalances) {\n sum += balance;\n }\n return sum / closingBalances.size();\n }\n\n public static void main(String[] args) {\n List closingBalances = Arrays.asList(100.0, 489.12, 12454.12, 1234.10, 823.05, 109.20, 5.27, 1542.25, 839.18, 83.99, 1295.01, 1.75);\n double averageBalance = calculateAverageBalance(closingBalances);\n System.out.println(\"The average account balance is: \" + averageBalance);\n }\n}", "import java.util.List;\n\npublic class AccountBalanceCalculator {\n\n /**\n * Calculates the average account balance based on the closing balances from the past twelve months.\n * \n * @param closingBalances A list of closing balances from the past twelve months.\n * @return The average account balance.\n */\n public static double calculateAverageBalance(List closingBalances) {\n double sum = 0.0;\n for (double balance : closingBalances) {\n sum += balance;\n }\n return sum / closingBalances.size();\n }\n\n public static void main(String[] args) {\n List closingBalances = Arrays.asList(100.0, 489.12, 12454.12, 1234.10, 823.05, 109.20, 5.27, 1542.25, 839.18, 83.99, 1295.01, 1.75);\n double averageBalance = calculateAverageBalance(closingBalances);\n System.out.println(\"The average account balance is: \" + averageBalance);\n }\n}", "import java.util.List;\n\npublic class AccountBalanceCalculator {\n\n /**\n * Calculates the average account balance based on the closing balances from the past twelve months.\n *\n * @param closingBalances A list of closing balances from the past twelve months.\n * @return The average account balance.\n */\n public static double calculateAverageBalance(List closingBalances) {\n double sum = 0.0;\n for (double balance : closingBalances) {\n sum += balance;\n }\n return sum / closingBalances.size();\n }\n\n public static void main(String[] args) {\n List closingBalances = Arrays.asList(100.0, 489.12, 12454.12, 1234.10, 823.05, 109.20, 5.27, 1542.25, 839.18, 83.99, 1295.01, 1.75);\n double averageBalance = calculateAverageBalance(closingBalances);\n System.out.println(\"The average account balance is: \" + averageBalance);\n }\n}", "import java.util.List;\n\npublic class AccountBalanceCalculator {\n\n /**\n * Calculates the average account balance based on the closing balances from the past twelve months.\n * \n * @param closingBalances A list of closing balances from the past twelve months.\n * @return The average account balance.\n */\n public static double calculateAverageBalance(List closingBalances) {\n if (closingBalances == null || closingBalances.isEmpty()) {\n throw new IllegalArgumentException(\"The list of closing balances cannot be null or empty.\");\n }\n \n double sum = 0.0;\n for (double balance : closingBalances) {\n sum += balance;\n }\n return sum / closingBalances.size();\n }\n\n public static void main(String[] args) {\n List closingBalances = Arrays.asList(100.0, 489.12, 12454.12, 1234.10, 823.05, 109.20, 5.27, 1542.25, 839.18, 83.99, 1295.01, 1.75);\n double averageBalance = calculateAverageBalance(closingBalances);\n System.out.println(\"The average account balance is: \" + averageBalance);\n }\n}", "import java.util.List;\n\npublic class AccountBalanceCalculator {\n\n /**\n * Calculates the average account balance based on the closing balances from the past twelve months.\n *\n * @param closingBalances A list of closing balances from the past twelve months.\n * @return The average account balance.\n */\n public static double calculateAverageBalance(List closingBalances) {\n if (closingBalances == null || closingBalances.isEmpty()) {\n throw new IllegalArgumentException(\"The list of closing balances cannot be null or empty.\");\n }\n\n double sum = 0.0;\n for (double balance : closingBalances) {\n sum += balance;\n }\n return sum / closingBalances.size();\n }\n\n public static void main(String[] args) {\n List closingBalances = Arrays.asList(100.0, 489.12, 12454.12, 1234.10, 823.05, 109.20, 5.27, 1542.25, 839.18, 83.99, 1295.01, 1.75);\n double averageBalance = calculateAverageBalance(closingBalances);\n System.out.println(\"The average account balance is: \" + averageBalance);\n }\n}" ], "moe_id": { "python": 0.0, "cpp": 0.9716, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0001, "php": 0.0, "typescript": 0.0283, "shell": 0.0 } }, { "source": "Write a Java function `public static int findNthLeapYear(int Y, int N)` to solve the following problem:\nGiven a positive integer Y indicating the start year, and a positive integer N,\nthis function finds the Nth leap year after the start year Y.\n\n@param Y The start year.\n@param N The position of the leap year to find.\n@return The Nth leap year after the start year Y.\n\nExample:\nfindNthLeapYear(2000, 4) => 2008\nfindNthLeapYear(1996, 10) => 2032", "ground-truth": null, "prediction": [ "public static int findNthLeapYear(int Y, int N) {\n int count = 0;\n int year = Y;\n while (count < N) {\n if (isLeapYear(year)) {\n count++;\n }\n year++;\n }\n return year - 1;\n}\n\nprivate static boolean isLeapYear(int year) {\n return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);\n}", "public static int findNthLeapYear(int Y, int N) {\n int leapYearCount = 0;\n int year = Y;\n\n while (leapYearCount < N) {\n if (isLeapYear(year)) {\n leapYearCount++;\n }\n year++;\n }\n\n return year - 1;\n}\n\nprivate static boolean isLeapYear(int year) {\n return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);\n}", "public static int findNthLeapYear(int Y, int N) {\n int leapYears = 0;\n int year = Y;\n while (leapYears < N) {\n if (isLeapYear(year)) {\n leapYears++;\n }\n year++;\n }\n return year - 1;\n}\n\nprivate static boolean isLeapYear(int year) {\n return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);\n}", "public static int findNthLeapYear(int Y, int N) {\n int leapYearCount = 0;\n int year = Y;\n while (leapYearCount < N) {\n if (isLeapYear(year)) {\n leapYearCount++;\n }\n year++;\n }\n return year - 1;\n}\n\nprivate static boolean isLeapYear(int year) {\n return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);\n}", "public static int findNthLeapYear(int Y, int N) {\n int leapYears = 0;\n int year = Y;\n while (leapYears < N) {\n if (isLeapYear(year)) {\n leapYears++;\n }\n year++;\n }\n return year - 1;\n}\n\nprivate static boolean isLeapYear(int year) {\n return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);\n}" ], "moe_id": { "python": 0.2, "cpp": 0.0091, "swift": 0.0734, "rust": 0.3937, "csharp": 0.0468, "java": 0.063, "php": 0.0035, "typescript": 0.2104, "shell": 0.0 } }, { "source": "Write a Java function `public static int calculateTimeNeeded(int N)` to solve the following problem:\nCalculate the time needed to obtain the reverse seating order.\nFor each person, the person who was originally on their left will be on their right, and the person who was originally on their right will be on their left.\n\n@param N the number of people\n@return the time needed in minutes\n\nExample:\n>>> calculateTimeNeeded(4)\n2\n>>> calculateTimeNeeded(5)\n4\n>>> calculateTimeNeeded(6)\n6", "ground-truth": null, "prediction": [ "public static int calculateTimeNeeded(int N) {\n int timeNeeded = 0;\n int left = 0;\n int right = N - 1;\n while (left < right) {\n timeNeeded += 2;\n left++;\n right--;\n }\n return timeNeeded;\n}", "public static int calculateTimeNeeded(int N) {\n int timeNeeded = 0;\n for (int i = 1; i <= N; i++) {\n timeNeeded += 2 * (N - i);\n }\n return timeNeeded;\n}", "public static int calculateTimeNeeded(int N) {\n int time = 0;\n for (int i = 0; i < N; i++) {\n time += N - i - 1;\n }\n return time;\n}", "public static int calculateTimeNeeded(int N) {\n int timeNeeded = 0;\n int left = 0;\n int right = N - 1;\n while (left < right) {\n timeNeeded += 2;\n left++;\n right--;\n }\n return timeNeeded;\n}", "public static int calculateTimeNeeded(int N) {\n int time = 0;\n int left = 0;\n int right = N - 1;\n while (left < right) {\n time += 2;\n left++;\n right--;\n }\n return time;\n}" ], "moe_id": { "python": 0.0, "cpp": 0.9998, "swift": 0.0002, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public List> permute(int[] nums)` to solve the following problem:\nGiven an array of distinct integers, return all possible permutations of the array.\n>>> permute(new int[]{1,2,3})\n[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]\n>>> permute(new int[]{0,1})\n[[0,1],[1,0]]\n>>> permute(new int[]{1})\n[[1]]", "ground-truth": null, "prediction": [ "import java.util.ArrayList;\nimport java.util.List;\n\npublic class Solution {\n public List> permute(int[] nums) {\n List> result = new ArrayList<>();\n permuteHelper(nums, 0, result);\n return result;\n }\n\n private void permuteHelper(int[] nums, int start, List> result) {\n if (start == nums.length - 1) {\n List list = new ArrayList<>();\n for (int num : nums) {\n list.add(num);\n }\n result.add(list);\n } else {\n for (int i = start; i < nums.length; i++) {\n swap(nums, start, i);\n permuteHelper(nums, start + 1, result);\n swap(nums, start, i);\n }\n }\n }\n\n private void swap(int[] nums, int i, int j) {\n int temp = nums[i];\n nums[i] = nums[j];\n nums[j] = temp;\n }\n\n public static void main(String[] args) {\n Solution solution = new Solution();\n System.out.println(solution.permute(new int[]{1, 2, 3}));\n System.out.println(solution.permute(new int[]{0, 1}));\n System.out.println(solution.permute(new int[]{1}));\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class Solution {\n public List> permute(int[] nums) {\n List> result = new ArrayList<>();\n permuteHelper(nums, 0, result);\n return result;\n }\n\n private void permuteHelper(int[] nums, int start, List> result) {\n if (start == nums.length) {\n List permutation = new ArrayList<>();\n for (int num : nums) {\n permutation.add(num);\n }\n result.add(permutation);\n } else {\n for (int i = start; i < nums.length; i++) {\n swap(nums, start, i);\n permuteHelper(nums, start + 1, result);\n swap(nums, start, i); // backtrack\n }\n }\n }\n\n private void swap(int[] nums, int i, int j) {\n int temp = nums[i];\n nums[i] = nums[j];\n nums[j] = temp;\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class Solution {\n public List> permute(int[] nums) {\n List> result = new ArrayList<>();\n permuteHelper(nums, 0, result);\n return result;\n }\n\n private void permuteHelper(int[] nums, int start, List> result) {\n if (start == nums.length) {\n List list = new ArrayList<>();\n for (int num : nums) {\n list.add(num);\n }\n result.add(list);\n } else {\n for (int i = start; i < nums.length; i++) {\n swap(nums, start, i);\n permuteHelper(nums, start + 1, result);\n swap(nums, start, i);\n }\n }\n }\n\n private void swap(int[] nums, int i, int j) {\n int temp = nums[i];\n nums[i] = nums[j];\n nums[j] = temp;\n }\n\n public static void main(String[] args) {\n Solution solution = new Solution();\n System.out.println(solution.permute(new int[]{1, 2, 3}));\n System.out.println(solution.permute(new int[]{0, 1}));\n System.out.println(solution.permute(new int[]{1}));\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class Solution {\n public List> permute(int[] nums) {\n List> result = new ArrayList<>();\n permuteHelper(nums, 0, result);\n return result;\n }\n\n private void permuteHelper(int[] nums, int start, List> result) {\n if (start == nums.length) {\n List permutation = new ArrayList<>();\n for (int num : nums) {\n permutation.add(num);\n }\n result.add(permutation);\n } else {\n for (int i = start; i < nums.length; i++) {\n swap(nums, start, i);\n permuteHelper(nums, start + 1, result);\n swap(nums, start, i); // backtrack\n }\n }\n }\n\n private void swap(int[] nums, int i, int j) {\n int temp = nums[i];\n nums[i] = nums[j];\n nums[j] = temp;\n }\n\n public static void main(String[] args) {\n Solution solution = new Solution();\n System.out.println(solution.permute(new int[]{1, 2, 3})); // [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]\n System.out.println(solution.permute(new int[]{0, 1})); // [[0,1],[1,0]]\n System.out.println(solution.permute(new int[]{1})); // [[1]]\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class Solution {\n public List> permute(int[] nums) {\n List> result = new ArrayList<>();\n permuteHelper(nums, 0, result);\n return result;\n }\n\n private void permuteHelper(int[] nums, int start, List> result) {\n if (start == nums.length) {\n List list = new ArrayList<>();\n for (int num : nums) {\n list.add(num);\n }\n result.add(list);\n } else {\n for (int i = start; i < nums.length; i++) {\n swap(nums, start, i);\n permuteHelper(nums, start + 1, result);\n swap(nums, start, i); // backtrack\n }\n }\n }\n\n private void swap(int[] nums, int i, int j) {\n int temp = nums[i];\n nums[i] = nums[j];\n nums[j] = temp;\n }\n\n public static void main(String[] args) {\n Solution solution = new Solution();\n System.out.println(solution.permute(new int[]{1, 2, 3})); // Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]\n System.out.println(solution.permute(new int[]{0, 1})); // Output: [[0,1],[1,0]]\n System.out.println(solution.permute(new int[]{1})); // Output: [[1]]\n }\n}" ], "moe_id": { "python": 0.0002, "cpp": 0.8702, "swift": 0.1173, "rust": 0.0039, "csharp": 0.0007, "java": 0.0001, "php": 0.0001, "typescript": 0.0076, "shell": 0.0 } }, { "source": "Write a Java function `public int findLargestSubstring(List strings)` to solve the following problem:\nGiven a number of case-sensitive strings, finds the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings.\n\nExample:\n>>> findLargestSubstring(Arrays.asList(\"ABCD\", \"BCDFF\", \"BRCD\"))\n2\n>>> findLargestSubstring(Arrays.asList(\"rose\", \"orchid\"))\n2", "ground-truth": null, "prediction": [ "import java.util.*;\n\npublic class StringSubstringFinder {\n public static int findLargestSubstring(List strings) {\n int max = 0;\n for (String s : strings) {\n for (int i = 0; i < s.length(); i++) {\n String sub = s.substring(i);\n if (strings.contains(sub) || strings.contains(sub.substring(1))) {\n max = Math.max(max, sub.length());\n }\n }\n }\n return max;\n }\n\n public static void main(String[] args) {\n List strings1 = Arrays.asList(\"ABCD\", \"BCDFF\", \"BRCD\");\n System.out.println(findLargestSubstring(strings1)); // Output: 2\n\n List strings2 = Arrays.asList(\"rose\", \"orchid\");\n System.out.println(findLargestSubstring(strings2)); // Output: 2\n }\n}", "import java.util.*;\n\npublic class StringFinder {\n public static int findLargestSubstring(List strings) {\n int maxLen = 0;\n for (String str : strings) {\n int len = str.length();\n for (int i = 0; i < len; i++) {\n String subStr = str.substring(i);\n if (strings.contains(subStr) || strings.contains(new StringBuilder(subStr).reverse().toString())) {\n maxLen = Math.max(maxLen, subStr.length());\n }\n }\n }\n return maxLen;\n }\n\n public static void main(String[] args) {\n List strings = Arrays.asList(\"ABCD\", \"BCDFF\", \"BRCD\");\n System.out.println(findLargestSubstring(strings)); // Output: 2\n\n strings = Arrays.asList(\"rose\", \"orchid\");\n System.out.println(findLargestSubstring(strings)); // Output: 2\n }\n}", "import java.util.*;\n\npublic class LargestSubstringFinder {\n\n public static int findLargestSubstring(List strings) {\n int max = 0;\n for (String s : strings) {\n for (int i = 0; i < s.length(); i++) {\n for (int j = i + 1; j <= s.length(); j++) {\n String substring = s.substring(i, j);\n if (strings.contains(substring) || strings.contains(new StringBuilder(substring).reverse().toString())) {\n max = Math.max(max, substring.length());\n }\n }\n }\n }\n return max;\n }\n\n public static void main(String[] args) {\n List strings = Arrays.asList(\"ABCD\", \"BCDFF\", \"BRCD\");\n System.out.println(findLargestSubstring(strings)); // Output: 2\n\n strings = Arrays.asList(\"rose\", \"orchid\");\n System.out.println(findLargestSubstring(strings)); // Output: 2\n }\n}", "import java.util.*;\n\npublic class StringSubstringFinder {\n\n public static int findLargestSubstring(List strings) {\n int max = 0;\n for (String s : strings) {\n for (int i = 0; i < s.length(); i++) {\n String reverse = new StringBuilder(s.substring(i)).reverse().toString();\n if (strings.contains(reverse)) {\n max = Math.max(max, s.length());\n }\n }\n }\n return max;\n }\n\n public static void main(String[] args) {\n List strings = Arrays.asList(\"ABCD\", \"BCDFF\", \"BRCD\");\n System.out.println(findLargestSubstring(strings)); // Output: 2\n\n strings = Arrays.asList(\"rose\", \"orchid\");\n System.out.println(findLargestSubstring(strings)); // Output: 2\n }\n}", "import java.util.*;\n\npublic class StringFinder {\n public static int findLargestSubstring(List strings) {\n int maxLen = 0;\n for (String str : strings) {\n for (int i = 0; i < str.length(); i++) {\n String reversed = new StringBuilder(str).reverse().toString();\n if (strings.contains(str) || strings.contains(reversed)) {\n maxLen = Math.max(maxLen, str.length());\n }\n }\n }\n return maxLen;\n }\n\n public static void main(String[] args) {\n List strings = Arrays.asList(\"ABCD\", \"BCDFF\", \"BRCD\");\n System.out.println(findLargestSubstring(strings)); // Output: 2\n\n strings = Arrays.asList(\"rose\", \"orchid\");\n System.out.println(findLargestSubstring(strings)); // Output: 2\n }\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static int countOilDeposits(char[][] grid)` to solve the following problem:\nGiven a grid representing a land divided into square plots, determine the number of distinct oil deposits.\n\nParameters:\ngrid (char[][]): The grid representing the land. Each character is either '*' for absence of oil or '@' for an oil pocket.\n\nReturns:\nint: The number of distinct oil deposits in the grid.\n\nExample:\n>>> countOilDeposits(new char[][] {{'*'}})\n0\n>>> countOilDeposits(new char[][] {{'*', '@', '*', '@', '*'}, {'*', '*', '@', '*', '*'}, {'*', '@', '*', '@', '*'}})\n1\n>>> countOilDeposits(new char[][] {{'@', '@', '*', '*', '*', '*', '@', '*'}})\n2", "ground-truth": null, "prediction": [ "public static int countOilDeposits(char[][] grid) {\n int count = 0;\n boolean[][] visited = new boolean[grid.length][grid[0].length];\n\n for (int i = 0; i < grid.length; i++) {\n for (int j = 0; j < grid[i].length; j++) {\n if (grid[i][j] == '@' && !visited[i][j]) {\n dfs(grid, i, j, visited);\n count++;\n }\n }\n }\n\n return count;\n}\n\nprivate static void dfs(char[][] grid, int i, int j, boolean[][] visited) {\n if (i < 0 || j < 0 || i >= grid.length || j >= grid[i].length || grid[i][j] != '@' || visited[i][j]) {\n return;\n }\n\n visited[i][j] = true;\n dfs(grid, i - 1, j, visited);\n dfs(grid, i + 1, j, visited);\n dfs(grid, i, j - 1, visited);\n dfs(grid, i, j + 1, visited);\n}", "public static int countOilDeposits(char[][] grid) {\n int count = 0;\n boolean[][] visited = new boolean[grid.length][grid[0].length];\n\n for (int i = 0; i < grid.length; i++) {\n for (int j = 0; j < grid[i].length; j++) {\n if (grid[i][j] == '@' && !visited[i][j]) {\n count++;\n dfs(grid, i, j, visited);\n }\n }\n }\n\n return count;\n}\n\nprivate static void dfs(char[][] grid, int i, int j, boolean[][] visited) {\n if (i < 0 || j < 0 || i >= grid.length || j >= grid[i].length || grid[i][j] != '@' || visited[i][j]) {\n return;\n }\n visited[i][j] = true;\n dfs(grid, i + 1, j, visited);\n dfs(grid, i - 1, j, visited);\n dfs(grid, i, j + 1, visited);\n dfs(grid, i, j - 1, visited);\n}", "public static int countOilDeposits(char[][] grid) {\n int count = 0;\n boolean[][] visited = new boolean[grid.length][grid[0].length];\n\n for (int i = 0; i < grid.length; i++) {\n for (int j = 0; j < grid[0].length; j++) {\n if (grid[i][j] == '@' && !visited[i][j]) {\n count++;\n dfs(grid, i, j, visited);\n }\n }\n }\n\n return count;\n}\n\nprivate static void dfs(char[][] grid, int i, int j, boolean[][] visited) {\n if (i < 0 || j < 0 || i >= grid.length || j >= grid[0].length || grid[i][j] != '@' || visited[i][j]) {\n return;\n }\n\n visited[i][j] = true;\n dfs(grid, i + 1, j, visited);\n dfs(grid, i - 1, j, visited);\n dfs(grid, i, j + 1, visited);\n dfs(grid, i, j - 1, visited);\n}", "public static int countOilDeposits(char[][] grid) {\n int count = 0;\n boolean[][] visited = new boolean[grid.length][grid[0].length];\n\n for (int i = 0; i < grid.length; i++) {\n for (int j = 0; j < grid[0].length; j++) {\n if (grid[i][j] == '@' && !visited[i][j]) {\n dfs(grid, i, j, visited);\n count++;\n }\n }\n }\n\n return count;\n}\n\nprivate static void dfs(char[][] grid, int i, int j, boolean[][] visited) {\n if (i < 0 || j < 0 || i >= grid.length || j >= grid[0].length || grid[i][j] != '@' || visited[i][j]) {\n return;\n }\n visited[i][j] = true;\n dfs(grid, i + 1, j, visited);\n dfs(grid, i - 1, j, visited);\n dfs(grid, i, j + 1, visited);\n dfs(grid, i, j - 1, visited);\n}", "public static int countOilDeposits(char[][] grid) {\n int count = 0;\n boolean[][] visited = new boolean[grid.length][grid[0].length];\n\n for (int i = 0; i < grid.length; i++) {\n for (int j = 0; j < grid[0].length; j++) {\n if (grid[i][j] == '@' && !visited[i][j]) {\n count++;\n dfs(grid, i, j, visited);\n }\n }\n }\n\n return count;\n}\n\nprivate static void dfs(char[][] grid, int i, int j, boolean[][] visited) {\n if (i < 0 || i >= grid.length || j < 0 || j >= grid[0].length || grid[i][j] != '@' || visited[i][j]) {\n return;\n }\n visited[i][j] = true;\n dfs(grid, i + 1, j, visited);\n dfs(grid, i - 1, j, visited);\n dfs(grid, i, j + 1, visited);\n dfs(grid, i, j - 1, visited);\n}" ], "moe_id": { "python": 0.0, "cpp": 0.9999, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0001, "shell": 0.0 } }, { "source": "Write a Java function `public static int maxRegions(int N)` to solve the following problem:\nGiven the number of triangles N, determine the maximum number of regions the plane can be divided into.\n\nExample:\n>>> maxRegions(1)\n2\n>>> maxRegions(2)\n8\n\n@param N the number of triangles\n@return the maximum number of regions", "ground-truth": null, "prediction": [ "public static int maxRegions(int N) {\n if (N == 0) {\n return 1;\n }\n return (int) (Math.pow(2, N) - 1);\n}", "public static int maxRegions(int N) {\n return (int) (Math.pow(2, N) - 1);\n}", "public static int maxRegions(int N) {\n return (int) (Math.pow(2, N) - 1);\n}", "public static int maxRegions(int N) {\n return (int) Math.pow(2, N);\n}", "public static int maxRegions(int N) {\n return (int) (Math.pow(4, N) + Math.pow(2, N) - 2);\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static int countPrefixWords(List wordList, String prefix)` to solve the following problem:\nCount the number of words in the given word list that have the given prefix.\n\n@param wordList: a list of words\n@param prefix: the prefix string\n@return the number of words with the given prefix\n\nExample:\n\n>>> countPrefixWords(Arrays.asList(\"banana\", \"band\", \"bee\", \"absolute\", \"acm\"), \"ba\")\n2\n\n>>> countPrefixWords(Arrays.asList(\"banana\", \"band\", \"bee\", \"absolute\", \"acm\"), \"b\")\n3\n\n>>> countPrefixWords(Arrays.asList(\"banana\", \"band\", \"bee\", \"absolute\", \"acm\"), \"band\")\n1", "ground-truth": null, "prediction": [ "import java.util.List;\n\npublic class WordCounter {\n\n public static int countPrefixWords(List wordList, String prefix) {\n int count = 0;\n for (String word : wordList) {\n if (word.startsWith(prefix)) {\n count++;\n }\n }\n return count;\n }\n\n public static void main(String[] args) {\n List wordList = Arrays.asList(\"banana\", \"band\", \"bee\", \"absolute\", \"acm\");\n System.out.println(countPrefixWords(wordList, \"ba\")); // Output: 2\n System.out.println(countPrefixWords(wordList, \"b\")); // Output: 3\n System.out.println(countPrefixWords(wordList, \"band\")); // Output: 1\n }\n}", "import java.util.*;\n\npublic class PrefixCounter {\n\n public static int countPrefixWords(List wordList, String prefix) {\n int count = 0;\n for (String word : wordList) {\n if (word.startsWith(prefix)) {\n count++;\n }\n }\n return count;\n }\n\n public static void main(String[] args) {\n List wordList = Arrays.asList(\"banana\", \"band\", \"bee\", \"absolute\", \"acm\");\n System.out.println(countPrefixWords(wordList, \"ba\")); // Output: 2\n System.out.println(countPrefixWords(wordList, \"b\")); // Output: 3\n System.out.println(countPrefixWords(wordList, \"band\")); // Output: 1\n }\n}", "import java.util.*;\n\npublic class PrefixCounter {\n public static int countPrefixWords(List wordList, String prefix) {\n int count = 0;\n for (String word : wordList) {\n if (word.startsWith(prefix)) {\n count++;\n }\n }\n return count;\n }\n\n public static void main(String[] args) {\n List wordList = Arrays.asList(\"banana\", \"band\", \"bee\", \"absolute\", \"acm\");\n System.out.println(countPrefixWords(wordList, \"ba\")); // Output: 2\n System.out.println(countPrefixWords(wordList, \"b\")); // Output: 3\n System.out.println(countPrefixWords(wordList, \"band\")); // Output: 1\n }\n}", "import java.util.List;\n\npublic class PrefixCounter {\n public static int countPrefixWords(List wordList, String prefix) {\n int count = 0;\n for (String word : wordList) {\n if (word.startsWith(prefix)) {\n count++;\n }\n }\n return count;\n }\n\n public static void main(String[] args) {\n List wordList = Arrays.asList(\"banana\", \"band\", \"bee\", \"absolute\", \"acm\");\n System.out.println(countPrefixWords(wordList, \"ba\")); // Output: 2\n System.out.println(countPrefixWords(wordList, \"b\")); // Output: 3\n System.out.println(countPrefixWords(wordList, \"band\")); // Output: 1\n }\n}", "import java.util.List;\n\npublic class WordCounter {\n public static int countPrefixWords(List wordList, String prefix) {\n int count = 0;\n for (String word : wordList) {\n if (word.startsWith(prefix)) {\n count++;\n }\n }\n return count;\n }\n\n public static void main(String[] args) {\n List wordList = Arrays.asList(\"banana\", \"band\", \"bee\", \"absolute\", \"acm\");\n System.out.println(countPrefixWords(wordList, \"ba\")); // Output: 2\n System.out.println(countPrefixWords(wordList, \"b\")); // Output: 3\n System.out.println(countPrefixWords(wordList, \"band\")); // Output: 1\n }\n}" ], "moe_id": { "python": 0.0347, "cpp": 0.0189, "swift": 0.0, "rust": 0.009, "csharp": 0.0007, "java": 0.0563, "php": 0.0, "typescript": 0.8803, "shell": 0.0 } }, { "source": "Write a Java function `public static int countDoubles(int[] numbers)` to solve the following problem:\nGiven a list of numbers, determine how many items in the list are twice some other item in the same list.\n\nExample:\n>>> countDoubles(new int[] {1, 4, 3, 2, 9, 7, 18, 22})\n3\n>>> countDoubles(new int[] {2, 4, 8, 10})\n2\n>>> countDoubles(new int[] {7, 5, 11, 13, 1, 3})\n0", "ground-truth": null, "prediction": [ "public static int countDoubles(int[] numbers) {\n int count = 0;\n Set seen = new HashSet<>();\n for (int num : numbers) {\n if (seen.contains(num * 2) || seen.contains(num / 2)) {\n count++;\n }\n seen.add(num);\n }\n return count;\n}", "public static int countDoubles(int[] numbers) {\n int count = 0;\n for (int i = 0; i < numbers.length; i++) {\n for (int j = i + 1; j < numbers.length; j++) {\n if (numbers[i] == 2 * numbers[j] || numbers[j] == 2 * numbers[i]) {\n count++;\n }\n }\n }\n return count;\n}", "public static int countDoubles(int[] numbers) {\n int count = 0;\n Set seen = new HashSet<>();\n for (int num : numbers) {\n if (seen.contains(num * 2)) {\n count++;\n }\n seen.add(num);\n }\n return count;\n}", "public static int countDoubles(int[] numbers) {\n int count = 0;\n Set seen = new HashSet<>();\n for (int num : numbers) {\n if (seen.contains(num * 2) || seen.contains(num / 2)) {\n count++;\n }\n seen.add(num);\n }\n return count;\n}", "public static int countDoubles(int[] numbers) {\n int count = 0;\n for (int i = 0; i < numbers.length; i++) {\n for (int j = i + 1; j < numbers.length; j++) {\n if (numbers[i] == 2 * numbers[j] || numbers[j] == 2 * numbers[i]) {\n count++;\n }\n }\n }\n return count;\n}" ], "moe_id": { "python": 0.2418, "cpp": 0.0003, "swift": 0.0258, "rust": 0.2184, "csharp": 0.034, "java": 0.1208, "php": 0.0011, "typescript": 0.3578, "shell": 0.0 } }, { "source": "Write a Java function `public static String canTravelMaze(int n, int[] start, int[] end, int[][] paths)` to solve the following problem:\nGiven the size of the n-teresting space, the starting and ending n-tersection coordinates, and the paths between adjacent n-tersections, determine if it is possible to travel from the starting n-tersection to the ending n-tersection.\n\nParameters:\n- n: the size of the n-teresting space\n- start: the starting n-tersection coordinates\n- end: the ending n-tersection coordinates\n- paths: paths between adjacent n-tersections in the n-teresting space\n\nOutput:\n- If travel is possible, return \"can be travelled\"\n- If travel is not possible, return \"cannot be travelled\"", "ground-truth": null, "prediction": [ "public static String canTravelMaze(int n, int[] start, int[] end, int[][] paths) {\n boolean[][] visited = new boolean[n][n];\n Queue queue = new LinkedList<>();\n queue.offer(start);\n visited[start[0]][start[1]] = true;\n\n while (!queue.isEmpty()) {\n int[] current = queue.poll();\n if (current[0] == end[0] && current[1] == end[1]) {\n return \"can be travelled\";\n }\n for (int[] path : paths) {\n int x = current[0] + path[0];\n int y = current[1] + path[1];\n if (x >= 0 && x < n && y >= 0 && y < n && !visited[x][y]) {\n queue.offer(new int[]{x, y});\n visited[x][y] = true;\n }\n }\n }\n return \"cannot be travelled\";\n}", "public static String canTravelMaze(int n, int[] start, int[] end, int[][] paths) {\n boolean[] visited = new boolean[n];\n Queue queue = new LinkedList<>();\n queue.offer(start);\n visited[start[0] * n + start[1]] = true;\n\n while (!queue.isEmpty()) {\n int[] current = queue.poll();\n if (current[0] == end[0] && current[1] == end[1]) {\n return \"can be travelled\";\n }\n for (int[] path : paths) {\n int nextX = current[0] + path[0];\n int nextY = current[1] + path[1];\n if (nextX >= 0 && nextX < n && nextY >= 0 && nextY < n && !visited[nextX * n + nextY]) {\n queue.offer(new int[]{nextX, nextY});\n visited[nextX * n + nextY] = true;\n }\n }\n }\n return \"cannot be travelled\";\n}", "public static String canTravelMaze(int n, int[] start, int[] end, int[][] paths) {\n boolean[] visited = new boolean[n * n];\n Queue queue = new LinkedList<>();\n queue.offer(start);\n visited[start[0] * n + start[1]] = true;\n\n while (!queue.isEmpty()) {\n int[] current = queue.poll();\n if (current[0] == end[0] && current[1] == end[1]) {\n return \"can be travelled\";\n }\n for (int[] path : paths) {\n int x = current[0] + path[0];\n int y = current[1] + path[1];\n if (x >= 0 && x < n && y >= 0 && y < n && !visited[x * n + y]) {\n queue.offer(new int[]{x, y});\n visited[x * n + y] = true;\n }\n }\n }\n return \"cannot be travelled\";\n}", "public static String canTravelMaze(int n, int[] start, int[] end, int[][] paths) {\n boolean[][] visited = new boolean[n][n];\n Queue queue = new LinkedList<>();\n queue.offer(start);\n\n while (!queue.isEmpty()) {\n int[] current = queue.poll();\n if (current[0] == end[0] && current[1] == end[1]) {\n return \"can be travelled\";\n }\n for (int[] path : paths) {\n int x = current[0] + path[0];\n int y = current[1] + path[1];\n if (x >= 0 && x < n && y >= 0 && y < n && !visited[x][y]) {\n queue.offer(new int[]{x, y});\n visited[x][y] = true;\n }\n }\n }\n return \"cannot be travelled\";\n}", "public static String canTravelMaze(int n, int[] start, int[] end, int[][] paths) {\n boolean[][] visited = new boolean[n][n];\n Queue queue = new LinkedList<>();\n queue.offer(start);\n visited[start[0]][start[1]] = true;\n\n while (!queue.isEmpty()) {\n int[] current = queue.poll();\n if (current[0] == end[0] && current[1] == end[1]) {\n return \"can be travelled\";\n }\n for (int[] path : paths) {\n int nextX = current[0] + path[0];\n int nextY = current[1] + path[1];\n if (nextX >= 0 && nextX < n && nextY >= 0 && nextY < n && !visited[nextX][nextY]) {\n queue.offer(new int[]{nextX, nextY});\n visited[nextX][nextY] = true;\n }\n }\n }\n return \"cannot be travelled\";\n}" ], "moe_id": { "python": 0.0, "cpp": 0.9999, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0001, "shell": 0.0 } }, { "source": "Write a Java function `public static String appx(String word1, String word2)` to solve the following problem:\nThe approximate value is calculated by counting the number of common letters\nand dividing it by the sum of the lengths of the two words.\n\n@param word1 The first word.\n@param word2 The second word.\n@return The approximate value as a reduced fraction.\n\n>>> appx(\"CAR\", \"CART\")\n\"appx(CAR, CART) = 6/7\"\n>>> appx(\"TURKEY\", \"CHICKEN\")\n\"appx(TURKEY, CHICKEN) = 4/13\"\n>>> appx(\"MONEY\", \"POVERTY\")\n\"appx(MONEY, POVERTY) = 1/3\"\n>>> appx(\"ROUGH\", \"PESKY\")\n\"appx(ROUGH, PESKY) = 0\"\n>>> appx(\"A\", \"A\")\n\"appx(A, A) = 1\"", "ground-truth": null, "prediction": [ "import java.util.*;\n\npublic class ApproximateValue {\n\n public static String appx(String word1, String word2) {\n int commonLetters = 0;\n for (int i = 0; i < word1.length(); i++) {\n for (int j = 0; j < word2.length(); j++) {\n if (word1.charAt(i) == word2.charAt(j)) {\n commonLetters++;\n break;\n }\n }\n }\n int numerator = commonLetters;\n int denominator = word1.length() + word2.length();\n int gcd = gcd(numerator, denominator);\n return \"appx(\" + word1 + \", \" + word2 + \") = \" + numerator + \"/\" + denominator + \" (\" + (numerator / gcd) + \"/\" + (denominator / gcd) + \")\";\n }\n\n private static int gcd(int a, int b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static void main(String[] args) {\n System.out.println(appx(\"CAR\", \"CART\"));\n System.out.println(appx(\"TURKEY\", \"CHICKEN\"));\n System.out.println(appx(\"MONEY\", \"POVERTY\"));\n System.out.println(appx(\"ROUGH\", \"PESKY\"));\n System.out.println(appx(\"A\", \"A\"));\n }\n}", "import java.util.stream.IntStream;\n\npublic class WordApproximateValue {\n\n public static String appx(String word1, String word2) {\n int commonLetters = IntStream.range(0, Math.min(word1.length(), word2.length()))\n .filter(i -> word1.charAt(i) == word2.charAt(i))\n .count();\n int totalLetters = word1.length() + word2.length();\n int gcd = gcd(commonLetters, totalLetters);\n return \"appx(\" + word1 + \", \" + word2 + \") = \" + commonLetters + \"/\" + totalLetters + \" (\" + commonLetters + \"/\" + totalLetters + \" = \" + (commonLetters / gcd) + \"/\" + (totalLetters / gcd) + \")\";\n }\n\n private static int gcd(int a, int b) {\n while (b != 0) {\n int temp = b;\n b = a % b;\n a = temp;\n }\n return a;\n }\n\n public static void main(String[] args) {\n System.out.println(appx(\"CAR\", \"CART\"));\n System.out.println(appx(\"TURKEY\", \"CHICKEN\"));\n System.out.println(appx(\"MONEY\", \"POVERTY\"));\n System.out.println(appx(\"ROUGH\", \"PESKY\"));\n System.out.println(appx(\"A\", \"A\"));\n }\n}", "import java.util.stream.IntStream;\n\npublic class AppxCalculator {\n\n public static String appx(String word1, String word2) {\n int commonLetters = IntStream.range(0, Math.min(word1.length(), word2.length()))\n .filter(i -> word1.charAt(i) == word2.charAt(i))\n .count();\n int totalLetters = word1.length() + word2.length();\n int gcd = gcd(commonLetters, totalLetters);\n return String.format(\"appx(%s, %s) = %d/%d\", word1, word2, commonLetters / gcd, totalLetters / gcd);\n }\n\n private static int gcd(int a, int b) {\n while (b != 0) {\n int temp = b;\n b = a % b;\n a = temp;\n }\n return a;\n }\n\n public static void main(String[] args) {\n System.out.println(appx(\"CAR\", \"CART\"));\n System.out.println(appx(\"TURKEY\", \"CHICKEN\"));\n System.out.println(appx(\"MONEY\", \"POVERTY\"));\n System.out.println(appx(\"ROUGH\", \"PESKY\"));\n System.out.println(appx(\"A\", \"A\"));\n }\n}", "public static String appx(String word1, String word2) {\n int commonLetters = 0;\n for (int i = 0; i < word1.length(); i++) {\n for (int j = 0; j < word2.length(); j++) {\n if (word1.charAt(i) == word2.charAt(j)) {\n commonLetters++;\n break;\n }\n }\n }\n int numerator = commonLetters;\n int denominator = word1.length() + word2.length();\n int gcd = gcd(numerator, denominator);\n return \"appx(\" + word1 + \", \" + word2 + \") = \" + numerator + \"/\" + denominator + \" (\" + (numerator / gcd) + \"/\" + (denominator / gcd) + \")\";\n}\n\nprivate static int gcd(int a, int b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n}", "import java.util.*;\n\npublic class ApproximateValue {\n public static String appx(String word1, String word2) {\n int commonLetters = 0;\n for (int i = 0; i < word1.length(); i++) {\n for (int j = 0; j < word2.length(); j++) {\n if (word1.charAt(i) == word2.charAt(j)) {\n commonLetters++;\n break;\n }\n }\n }\n int numerator = commonLetters;\n int denominator = word1.length() + word2.length();\n int gcd = gcd(numerator, denominator);\n return \"appx(\" + word1 + \", \" + word2 + \") = \" + numerator + \"/\" + denominator + \" (\" + (numerator / gcd) + \"/\" + (denominator / gcd) + \")\";\n }\n\n private static int gcd(int a, int b) {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n public static void main(String[] args) {\n System.out.println(appx(\"CAR\", \"CART\"));\n System.out.println(appx(\"TURKEY\", \"CHICKEN\"));\n System.out.println(appx(\"MONEY\", \"POVERTY\"));\n System.out.println(appx(\"ROUGH\", \"PESKY\"));\n System.out.println(appx(\"A\", \"A\"));\n }\n}" ], "moe_id": { "python": 0.2439, "cpp": 0.016, "swift": 0.0015, "rust": 0.3055, "csharp": 0.0206, "java": 0.2869, "php": 0.0017, "typescript": 0.1239, "shell": 0.0 } }, { "source": "Write a Java function `public static String convertDatesToWeekdays(String date)` to solve the following problem:\nGiven a date in the format \"MM dd yyyy\", return the weekday of the date.\n\nExample:\n>>> convertDatesToWeekdays(\"11 15 1997\")\n\"November 15, 1997 is a Saturday\"\n>>> convertDatesToWeekdays(\"01 01 2000\")\n\"January 1, 2000 is a Saturday\"\n>>> convertDatesToWeekdays(\"07 04 1998\")\n\"July 4, 1998 is a Saturday\"", "ground-truth": null, "prediction": [ "import java.time.LocalDate;\nimport java.time.format.DateTimeFormatter;\n\npublic class DateConverter {\n public static String convertDatesToWeekdays(String date) {\n DateTimeFormatter formatter = DateTimeFormatter.ofPattern(\"MM dd yyyy\");\n LocalDate dateObj = LocalDate.parse(date, formatter);\n String weekday = dateObj.getDayOfWeek().toString();\n return date + \" is a \" + weekday;\n }\n\n public static void main(String[] args) {\n System.out.println(convertDatesToWeekdays(\"11 15 1997\"));\n System.out.println(convertDatesToWeekdays(\"01 01 2000\"));\n System.out.println(convertDatesToWeekdays(\"07 04 1998\"));\n }\n}", "import java.time.LocalDate;\nimport java.time.format.DateTimeFormatter;\n\npublic class DateConverter {\n public static String convertDatesToWeekdays(String date) {\n DateTimeFormatter formatter = DateTimeFormatter.ofPattern(\"MM dd yyyy\");\n LocalDate dateObj = LocalDate.parse(date, formatter);\n String weekday = dateObj.getDayOfWeek().toString();\n return date + \" is a \" + weekday;\n }\n\n public static void main(String[] args) {\n System.out.println(convertDatesToWeekdays(\"11 15 1997\"));\n System.out.println(convertDatesToWeekdays(\"01 01 2000\"));\n System.out.println(convertDatesToWeekdays(\"07 04 1998\"));\n }\n}", "import java.time.LocalDate;\nimport java.time.format.DateTimeFormatter;\nimport java.time.format.TextStyle;\nimport java.util.Locale;\n\npublic class DateConverter {\n public static String convertDatesToWeekdays(String date) {\n DateTimeFormatter formatter = DateTimeFormatter.ofPattern(\"MM dd yyyy\");\n LocalDate dateObj = LocalDate.parse(date, formatter);\n String weekday = dateObj.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.ENGLISH);\n return date + \" is a \" + weekday;\n }\n\n public static void main(String[] args) {\n System.out.println(convertDatesToWeekdays(\"11 15 1997\"));\n System.out.println(convertDatesToWeekdays(\"01 01 2000\"));\n System.out.println(convertDatesToWeekdays(\"07 04 1998\"));\n }\n}", "import java.time.LocalDate;\nimport java.time.format.DateTimeFormatter;\nimport java.time.format.TextStyle;\nimport java.util.Locale;\n\npublic class DateConverter {\n public static String convertDatesToWeekdays(String date) {\n DateTimeFormatter formatter = DateTimeFormatter.ofPattern(\"MM dd yyyy\");\n LocalDate dateObj = LocalDate.parse(date, formatter);\n String weekday = dateObj.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.ENGLISH);\n return date + \" is a \" + weekday;\n }\n\n public static void main(String[] args) {\n System.out.println(convertDatesToWeekdays(\"11 15 1997\"));\n System.out.println(convertDatesToWeekdays(\"01 01 2000\"));\n System.out.println(convertDatesToWeekdays(\"07 04 1998\"));\n }\n}", "import java.time.LocalDate;\nimport java.time.format.DateTimeFormatter;\nimport java.time.format.TextStyle;\nimport java.util.Locale;\n\npublic class DateConverter {\n\n public static String convertDatesToWeekdays(String date) {\n DateTimeFormatter formatter = DateTimeFormatter.ofPattern(\"MM dd yyyy\");\n LocalDate dateObj = LocalDate.parse(date, formatter);\n String weekday = dateObj.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.ENGLISH);\n return date + \" is a \" + weekday;\n }\n\n public static void main(String[] args) {\n System.out.println(convertDatesToWeekdays(\"11 15 1997\"));\n System.out.println(convertDatesToWeekdays(\"01 01 2000\"));\n System.out.println(convertDatesToWeekdays(\"07 04 1998\"));\n }\n}" ], "moe_id": { "python": 0.03, "cpp": 0.0, "swift": 0.0006, "rust": 0.0424, "csharp": 0.0078, "java": 0.0473, "php": 0.0003, "typescript": 0.8717, "shell": 0.0 } }, { "source": "Write a Java function `public int[] twoSum(int[] nums, int target)` to solve the following problem:\nGiven an array of integers nums and an integer target,\nfind two numbers such that they add up to target and return their indices.\nYou may assume that each input would have exactly one solution,\nand you may not use the same element twice.\nYou can return the answer in any order.\n\nExample 1:\nInput: nums = [2,7,11,15], target = 9\nOutput: [0,1]\nExplanation: Because nums[0] + nums[1] == 9, we return [0, 1].\n\nExample 2:\nInput: nums = [3,2,4], target = 6\nOutput: [1,2]\n\nExample 3:\nInput: nums = [3,3], target = 6\nOutput: [0,1]", "ground-truth": null, "prediction": [ "public int[] twoSum(int[] nums, int target) {\n Map map = new HashMap<>();\n for (int i = 0; i < nums.length; i++) {\n int complement = target - nums[i];\n if (map.containsKey(complement)) {\n return new int[] { map.get(complement), i };\n }\n map.put(nums[i], i);\n }\n throw new IllegalArgumentException(\"No two sum solution\");\n}", "public int[] twoSum(int[] nums, int target) {\n Map map = new HashMap<>();\n for (int i = 0; i < nums.length; i++) {\n int complement = target - nums[i];\n if (map.containsKey(complement)) {\n return new int[] { map.get(complement), i };\n }\n map.put(nums[i], i);\n }\n throw new IllegalArgumentException(\"No two sum solution\");\n}", "import java.util.HashMap;\n\npublic class Solution {\n public int[] twoSum(int[] nums, int target) {\n HashMap map = new HashMap<>();\n for (int i = 0; i < nums.length; i++) {\n int complement = target - nums[i];\n if (map.containsKey(complement)) {\n return new int[] { map.get(complement), i };\n }\n map.put(nums[i], i);\n }\n return new int[] {}; // No solution found\n }\n}", "import java.util.HashMap;\n\npublic class Solution {\n public int[] twoSum(int[] nums, int target) {\n HashMap map = new HashMap<>();\n for (int i = 0; i < nums.length; i++) {\n int complement = target - nums[i];\n if (map.containsKey(complement)) {\n return new int[] { map.get(complement), i };\n }\n map.put(nums[i], i);\n }\n throw new IllegalArgumentException(\"No two sum solution\");\n }\n}", "public int[] twoSum(int[] nums, int target) {\n Map map = new HashMap<>();\n for (int i = 0; i < nums.length; i++) {\n int complement = target - nums[i];\n if (map.containsKey(complement)) {\n return new int[] { map.get(complement), i };\n }\n map.put(nums[i], i);\n }\n throw new IllegalArgumentException(\"No two sum solution\");\n}" ], "moe_id": { "python": 0.0, "cpp": 0.9999, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0001, "shell": 0.0 } }, { "source": "Write a Java function `public int search(int[] nums, int target)` to solve the following problem:\nSearch for the target value in the rotated sorted array.\nIf the target value exists, return its index; otherwise, return -1.\nThe array nums is rotated at some unknown pivot k, where 0 <= k < nums.length.\nThe time complexity of the algorithm must be O(log n).\n\n>>> search(new int[]{4,5,6,7,0,1,2}, 0)\n4\n>>> search(new int[]{4,5,6,7,0,1,2}, 3)\n-1\n>>> search(new int[]{1}, 0)\n-1", "ground-truth": null, "prediction": [ "public int search(int[] nums, int target) {\n int left = 0, right = nums.length - 1;\n \n while (left <= right) {\n int mid = left + (right - left) / 2;\n if (nums[mid] == target) {\n return mid;\n }\n \n if (nums[left] <= nums[mid]) { // Left half is sorted\n if (nums[left] <= target && target < nums[mid]) {\n right = mid - 1;\n } else {\n left = mid + 1;\n }\n } else { // Right half is sorted\n if (nums[mid] < target && target <= nums[right]) {\n left = mid + 1;\n } else {\n right = mid - 1;\n }\n }\n }\n \n return -1;\n}", "public int search(int[] nums, int target) {\n int left = 0;\n int right = nums.length - 1;\n \n while (left <= right) {\n int mid = left + (right - left) / 2;\n if (nums[mid] == target) {\n return mid;\n }\n \n if (nums[left] <= nums[mid]) { // Left half is sorted\n if (nums[left] <= target && target < nums[mid]) {\n right = mid - 1;\n } else {\n left = mid + 1;\n }\n } else { // Right half is sorted\n if (nums[mid] < target && target <= nums[right]) {\n left = mid + 1;\n } else {\n right = mid - 1;\n }\n }\n }\n \n return -1;\n}", "public int search(int[] nums, int target) {\n int left = 0, right = nums.length - 1;\n \n while (left <= right) {\n int mid = left + (right - left) / 2;\n \n if (nums[mid] == target) {\n return mid;\n }\n \n if (nums[left] <= nums[mid]) {\n if (nums[left] <= target && target < nums[mid]) {\n right = mid - 1;\n } else {\n left = mid + 1;\n }\n } else {\n if (nums[mid] < target && target <= nums[right]) {\n left = mid + 1;\n } else {\n right = mid - 1;\n }\n }\n }\n \n return -1;\n}", "public int search(int[] nums, int target) {\n int left = 0, right = nums.length - 1;\n \n while (left <= right) {\n int mid = left + (right - left) / 2;\n \n if (nums[mid] == target) {\n return mid;\n }\n \n if (nums[left] <= nums[mid]) {\n if (nums[left] <= target && target < nums[mid]) {\n right = mid - 1;\n } else {\n left = mid + 1;\n }\n } else {\n if (nums[mid] < target && target <= nums[right]) {\n left = mid + 1;\n } else {\n right = mid - 1;\n }\n }\n }\n \n return -1;\n}", "public int search(int[] nums, int target) {\n int left = 0, right = nums.length - 1;\n while (left <= right) {\n int mid = left + (right - left) / 2;\n if (nums[mid] == target) {\n return mid;\n }\n if (nums[left] <= nums[mid]) { // Left half is sorted\n if (nums[left] <= target && target < nums[mid]) {\n right = mid - 1;\n } else {\n left = mid + 1;\n }\n } else { // Right half is sorted\n if (nums[mid] < target && target <= nums[right]) {\n left = mid + 1;\n } else {\n right = mid - 1;\n }\n }\n }\n return -1;\n}" ], "moe_id": { "python": 0.3673, "cpp": 0.0, "swift": 0.0009, "rust": 0.1124, "csharp": 0.0157, "java": 0.2197, "php": 0.0002, "typescript": 0.284, "shell": 0.0 } }, { "source": "Write a Java function `public double trimMean(int[] arr)` to solve the following problem:\nGiven an integer array arr, calculate the mean of the remaining elements after removing the smallest 5% and largest 5% of the elements.\nReturn the mean with an error within 10^-5.\n\nExample 1:\nInput: arr = [1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3]\nOutput: 2.00000\n\nExample 2:\nInput: arr = [6,2,7,5,1,2,0,3,10,2,5,0,5,5,0,8,7,6,8,0]\nOutput: 4.00000\n\nExample 3:\nInput: arr = [6,0,7,0,7,5,7,8,3,4,0,7,8,1,6,8,1,1,2,4,8,1,9,5,4,3,8,5,10,8,6,6,1,0,6,10,8,2,3,4]\nOutput: 4.77778\n\nExample 4:\nInput: arr = [9,7,8,7,7,8,4,4,6,8,8,7,6,8,8,9,2,6,0,0,1,10,8,6,3,3,5,1,10,9,0,7,10,0,10,4,1,10,6,9,3,6,0,0,2,7,0,6,7,2,9,7,7,3,0,1,6,1,10,3]\nOutput: 5.27778\n\nExample 5:\nInput: arr = [4,8,4,10,0,7,1,3,7,8,8,3,4,1,6,2,1,1,8,0,9,8,0,3,9,10,3,10,1,10,7,3,2,1,4,9,10,7,6,4,0,8,5,1,2,1,6,2,5,0,7,10,9,10,3,7,10,5,8,5,7,6,7,6,10,9,5,10,5,5,7,2,10,7,7,8,2,0,1,1]\nOutput: 5.29167", "ground-truth": null, "prediction": [ "import java.util.Arrays;\n\npublic class Solution {\n public double trimMean(int[] arr) {\n Arrays.sort(arr);\n int n = arr.length;\n int remove = (int) (0.05 * n);\n int sum = 0;\n for (int i = remove; i < n - remove; i++) {\n sum += arr[i];\n }\n return (double) sum / (n - 2 * remove);\n }\n}", "public double trimMean(int[] arr) {\n Arrays.sort(arr);\n int n = arr.length;\n int remove = (int) (0.05 * n);\n int sum = 0;\n for (int i = remove; i < n - remove; i++) {\n sum += arr[i];\n }\n return (double) sum / (n - 2 * remove);\n}", "public double trimMean(int[] arr) {\n Arrays.sort(arr);\n int n = arr.length;\n int remove = (int) (0.05 * n);\n int sum = 0;\n for (int i = remove; i < n - remove; i++) {\n sum += arr[i];\n }\n return (double) sum / (n - 2 * remove);\n}", "public double trimMean(int[] arr) {\n Arrays.sort(arr);\n int n = arr.length;\n int remove = (int) (0.05 * n);\n int sum = 0;\n for (int i = remove; i < n - remove; i++) {\n sum += arr[i];\n }\n return (double) sum / (n - 2 * remove);\n}", "public double trimMean(int[] arr) {\n Arrays.sort(arr);\n int n = arr.length;\n int remove = (int) (0.05 * n);\n int sum = 0;\n for (int i = remove; i < n - remove; i++) {\n sum += arr[i];\n }\n return (double) sum / (n - 2 * remove);\n}" ], "moe_id": { "python": 0.0, "cpp": 0.0, "swift": 0.0, "rust": 0.0626, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.9373, "shell": 0.0 } }, { "source": "Write a Java function `public boolean canArrange(int[] arr, int k)` to solve the following problem:\nCheck if it is possible to divide the array into n/2 pairs such that the sum of each pair is divisible by k.\n\n@param arr the input integer array\n@param k the divisor\n@return true if it is possible, false otherwise\n\nExample:\nInput: arr = [1,2,3,4,5,10,6,7,8,9], k = 5\nOutput: true\nExplanation: The pairs are (1,9), (2,8), (3,7), (4,6), (5,10), and the sum of each pair is divisible by 5.\n\nInput: arr = [1,2,3,4,5,6], k = 7\nOutput: true\nExplanation: The pairs are (1,6), (2,5), (3,4), and the sum of each pair is divisible by 7.\n\nInput: arr = [1,2,3,4,5,6], k = 10\nOutput: false\nExplanation: It is not possible to divide the array into n/2 pairs such that the sum of each pair is divisible by 10.", "ground-truth": null, "prediction": [ "public boolean canArrange(int[] arr, int k) {\n int[] remainder = new int[k];\n for (int num : arr) {\n int r = (num % k + k) % k;\n remainder[r]++;\n }\n for (int i = 1; i < k; i++) {\n if (remainder[i] != remainder[k - i]) {\n return false;\n }\n }\n return remainder[0] % 2 == 0;\n}", "public boolean canArrange(int[] arr, int k) {\n int[] remainderCount = new int[k];\n for (int num : arr) {\n int remainder = num % k;\n if (remainder < 0) {\n remainder += k;\n }\n remainderCount[remainder]++;\n }\n for (int i = 1; i < k / 2; i++) {\n if (remainderCount[i] != remainderCount[k - i]) {\n return false;\n }\n }\n return remainderCount[0] % 2 == 0;\n}", "public boolean canArrange(int[] arr, int k) {\n int[] remainderCount = new int[k];\n for (int num : arr) {\n int remainder = num % k;\n if (remainder < 0) {\n remainder += k;\n }\n remainderCount[remainder]++;\n }\n for (int i = 1; i < k / 2; i++) {\n if (remainderCount[i] != remainderCount[k - i]) {\n return false;\n }\n }\n return remainderCount[0] % 2 == 0;\n}", "public boolean canArrange(int[] arr, int k) {\n int[] count = new int[k];\n for (int num : arr) {\n int remainder = num % k;\n if (remainder < 0) {\n remainder += k;\n }\n count[remainder]++;\n }\n for (int i = 0; i < k; i++) {\n if (count[i] != count[k - i]) {\n return false;\n }\n }\n return true;\n}", "public boolean canArrange(int[] arr, int k) {\n int[] remainder = new int[k];\n for (int num : arr) {\n int r = (num % k + k) % k;\n remainder[r]++;\n }\n for (int i = 1; i < k; i++) {\n if (remainder[i] != remainder[k - i]) {\n return false;\n }\n }\n return remainder[0] % 2 == 0;\n}" ], "moe_id": { "python": 0.0006, "cpp": 0.9985, "swift": 0.0001, "rust": 0.0001, "csharp": 0.0003, "java": 0.0001, "php": 0.0, "typescript": 0.0004, "shell": 0.0 } }, { "source": "Write a Java function `public int minTime(int n, int[][] edges, boolean[] hasApple)` to solve the following problem:\nGiven a tree with n nodes and edges, and a boolean array hasApple indicating if each node has an apple.\nStarting from node 0, return the minimum time required to collect all the apples and return to node 0.\n\nExample:\nInput: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,true,false,true,true,false]\nOutput: 8\n\nInput: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,true,false,false,true,false]\nOutput: 6\n\nInput: n = 7, edges = [[0,1],[0,2],[1,4],[1,5],[2,3],[2,6]], hasApple = [false,false,false,false,false,false,false]\nOutput: 0", "ground-truth": null, "prediction": [ "import java.util.*;\n\npublic class AppleCollector {\n public int minTime(int n, int[][] edges, boolean[] hasApple) {\n Map> graph = new HashMap<>();\n for (int[] edge : edges) {\n int parent = edge[0];\n int child = edge[1];\n graph.computeIfAbsent(parent, k -> new ArrayList<>()).add(child);\n }\n\n boolean[] visited = new boolean[n];\n return dfs(0, graph, hasApple, visited);\n }\n\n private int dfs(int node, Map> graph, boolean[] hasApple, boolean[] visited) {\n visited[node] = true;\n int time = 0;\n for (int child : graph.getOrDefault(node, Collections.emptyList())) {\n if (!visited[child]) {\n time += dfs(child, graph, hasApple, visited);\n }\n }\n if (node != 0 && (hasApple[node] || time > 0)) {\n time += 2;\n }\n return time;\n }\n\n public static void main(String[] args) {\n AppleCollector collector = new AppleCollector();\n int n = 7;\n int[][] edges = {{0,1},{0,2},{1,4},{1,5},{2,3},{2,6}};\n boolean[] hasApple = {false,false,true,false,true,true,false};\n System.out.println(collector.minTime(n, edges, hasApple)); // Output: 8\n\n n = 7;\n edges = {{0,1},{0,2},{1,4},{1,5},{2,3},{2,6}};\n hasApple = {false,false,true,false,false,true,false};\n System.out.println(collector.minTime(n, edges, hasApple)); // Output: 6\n\n n = 7;\n edges = {{0,1},{0,2},{1,4},{1,5},{2,3},{2,6}};\n hasApple = {false,false,false,false,false,false,false};\n System.out.println(collector.minTime(n, edges, hasApple)); // Output: 0\n }\n}", "import java.util.*;\n\npublic class Solution {\n public int minTime(int n, int[][] edges, boolean[] hasApple) {\n List> graph = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n graph.add(new ArrayList<>());\n }\n for (int[] edge : edges) {\n graph.get(edge[0]).add(edge[1]);\n graph.get(edge[1]).add(edge[0]);\n }\n return dfs(0, -1, graph, hasApple);\n }\n\n private int dfs(int node, int parent, List> graph, boolean[] hasApple) {\n int time = 0;\n for (int child : graph.get(node)) {\n if (child != parent) {\n int childTime = dfs(child, node, graph, hasApple);\n if (childTime > 0 || hasApple[child]) {\n time += childTime + 2;\n }\n }\n }\n return time;\n }\n}", "import java.util.*;\n\npublic class AppleCollector {\n public int minTime(int n, int[][] edges, boolean[] hasApple) {\n List> graph = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n graph.add(new ArrayList<>());\n }\n for (int[] edge : edges) {\n graph.get(edge[0]).add(edge[1]);\n graph.get(edge[1]).add(edge[0]);\n }\n return dfs(0, -1, graph, hasApple);\n }\n\n private int dfs(int node, int parent, List> graph, boolean[] hasApple) {\n int time = 0;\n for (int child : graph.get(node)) {\n if (child != parent) {\n int childTime = dfs(child, node, graph, hasApple);\n if (childTime > 0 || hasApple[child]) {\n time += childTime + 2;\n }\n }\n }\n return time;\n }\n}", "import java.util.*;\n\nclass Solution {\n public int minTime(int n, int[][] edges, boolean[] hasApple) {\n Map> graph = new HashMap<>();\n for (int[] edge : edges) {\n int u = edge[0];\n int v = edge[1];\n graph.computeIfAbsent(u, k -> new ArrayList<>()).add(v);\n graph.computeIfAbsent(v, k -> new ArrayList<>()).add(u);\n }\n \n return dfs(0, -1, graph, hasApple);\n }\n \n private int dfs(int node, int parent, Map> graph, boolean[] hasApple) {\n int time = 0;\n for (int child : graph.getOrDefault(node, Collections.emptyList())) {\n if (child != parent) {\n int childTime = dfs(child, node, graph, hasApple);\n if (childTime > 0 || hasApple[child]) {\n time += childTime + 2;\n }\n }\n }\n return time;\n }\n}", "import java.util.*;\n\npublic class Solution {\n public int minTime(int n, int[][] edges, boolean[] hasApple) {\n List> graph = new ArrayList<>();\n for (int i = 0; i < n; i++) {\n graph.add(new ArrayList<>());\n }\n for (int[] edge : edges) {\n graph.get(edge[0]).add(edge[1]);\n graph.get(edge[1]).add(edge[0]);\n }\n return dfs(0, -1, graph, hasApple);\n }\n\n private int dfs(int node, int parent, List> graph, boolean[] hasApple) {\n int time = 0;\n for (int child : graph.get(node)) {\n if (child != parent) {\n time += dfs(child, node, graph, hasApple);\n }\n }\n if (node != 0 && (time > 0 || hasApple[node])) {\n time += 2;\n }\n return time;\n }\n}" ], "moe_id": { "python": 0.0008, "cpp": 0.5994, "swift": 0.0, "rust": 0.0016, "csharp": 0.0, "java": 0.0007, "php": 0.0, "typescript": 0.3974, "shell": 0.0 } }, { "source": "Write a Java function `public String sortString(String s)` to solve the following problem:\nGiven a string s. You should re-order the string using the following algorithm:\n1. Pick the smallest character from s and append it to the result.\n2. Pick the smallest character from s which is greater than the last appended character to the result and append it.\n3. Repeat step 2 until you cannot pick more characters.\n4. Pick the largest character from s and append it to the result.\n5. Pick the largest character from s which is smaller than the last appended character to the result and append it.\n6. Repeat step 5 until you cannot pick more characters.\n7. Repeat the steps from 1 to 6 until you pick all characters from s.\nIn each step, If the smallest or the largest character appears more than once you can choose any occurrence and append it to the result.\nReturn the result string after sorting s with this algorithm.", "ground-truth": null, "prediction": [ "public String sortString(String s) {\n int[] count = new int[26];\n for (char c : s.toCharArray()) {\n count[c - 'a']++;\n }\n\n StringBuilder result = new StringBuilder();\n while (result.length() < s.length()) {\n for (int i = 0; i < 26; i++) {\n if (count[i] > 0) {\n result.append((char) (i + 'a'));\n count[i]--;\n }\n }\n for (int i = 25; i >= 0; i--) {\n if (count[i] > 0) {\n result.append((char) (i + 'a'));\n count[i]--;\n }\n }\n }\n return result.toString();\n}", "public String sortString(String s) {\n int[] count = new int[26];\n for (char c : s.toCharArray()) {\n count[c - 'a']++;\n }\n StringBuilder result = new StringBuilder();\n while (result.length() < s.length()) {\n for (int i = 0; i < 26; i++) {\n if (count[i] > 0) {\n result.append((char) (i + 'a'));\n count[i]--;\n }\n }\n for (int i = 25; i >= 0; i--) {\n if (count[i] > 0) {\n result.append((char) (i + 'a'));\n count[i]--;\n }\n }\n }\n return result.toString();\n}", "public String sortString(String s) {\n StringBuilder sb = new StringBuilder();\n int[] count = new int[26];\n for (char c : s.toCharArray()) {\n count[c - 'a']++;\n }\n int n = s.length();\n while (n > 0) {\n for (int i = 0; i < 26; i++) {\n if (count[i] > 0) {\n sb.append((char) (i + 'a'));\n count[i]--;\n n--;\n }\n }\n for (int i = 25; i >= 0; i--) {\n if (count[i] > 0) {\n sb.append((char) (i + 'a'));\n count[i]--;\n n--;\n }\n }\n }\n return sb.toString();\n}", "public String sortString(String s) {\n int[] count = new int[26];\n for (char c : s.toCharArray()) {\n count[c - 'a']++;\n }\n StringBuilder result = new StringBuilder();\n while (result.length() < s.length()) {\n for (int i = 0; i < 26; i++) {\n if (count[i] > 0) {\n result.append((char) (i + 'a'));\n count[i]--;\n }\n }\n for (int i = 25; i >= 0; i--) {\n if (count[i] > 0) {\n result.append((char) (i + 'a'));\n count[i]--;\n }\n }\n }\n return result.toString();\n}", "public String sortString(String s) {\n int[] count = new int[26];\n for (char c : s.toCharArray()) {\n count[c - 'a']++;\n }\n StringBuilder sb = new StringBuilder();\n while (s.length() > 0) {\n for (int i = 0; i < 26; i++) {\n if (count[i] > 0) {\n sb.append((char) (i + 'a'));\n count[i]--;\n s = s.substring(1);\n }\n }\n for (int i = 25; i >= 0; i--) {\n if (count[i] > 0) {\n sb.append((char) (i + 'a'));\n count[i]--;\n s = s.substring(1);\n }\n }\n }\n return sb.toString();\n}" ], "moe_id": { "python": 0.0052, "cpp": 0.9892, "swift": 0.0004, "rust": 0.0006, "csharp": 0.0006, "java": 0.004, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public boolean splitArraySameAverage(int[] nums)` to solve the following problem:\nCheck if it is possible to split the given integer array into two non-empty arrays\nwith the same average.\n\n>>> splitArraySameAverage(new int[]{1,2,3,4,5,6,7,8})\ntrue\n\n>>> splitArraySameAverage(new int[]{3,1})\nfalse", "ground-truth": null, "prediction": [ "import java.util.Arrays;\n\npublic class Solution {\n public boolean splitArraySameAverage(int[] nums) {\n int n = nums.length;\n int sum = Arrays.stream(nums).sum();\n int target = sum / n;\n int[] prefixSum = new int[n + 1];\n for (int i = 1; i <= n; i++) {\n prefixSum[i] = prefixSum[i - 1] + nums[i - 1];\n }\n for (int i = 1; i <= n; i++) {\n if (prefixSum[i] * n == target * (i + n)) {\n return true;\n }\n for (int j = i + 1; j <= n; j++) {\n if (prefixSum[j] - prefixSum[i] == target) {\n return true;\n }\n }\n }\n return false;\n }\n}", "import java.util.Arrays;\n\npublic class Solution {\n public boolean splitArraySameAverage(int[] nums) {\n int n = nums.length;\n int sum = Arrays.stream(nums).sum();\n int target = sum / 2;\n int[] prefixSum = new int[n + 1];\n for (int i = 1; i <= n; i++) {\n prefixSum[i] = prefixSum[i - 1] + nums[i - 1];\n }\n for (int i = 1; i <= n; i++) {\n if (prefixSum[i] == target) {\n return true;\n }\n }\n for (int i = 1; i <= n; i++) {\n for (int j = i + 1; j <= n; j++) {\n if (prefixSum[j] - prefixSum[i] == target) {\n return true;\n }\n }\n }\n return false;\n }\n}", "import java.util.Arrays;\n\npublic class Solution {\n public boolean splitArraySameAverage(int[] nums) {\n int n = nums.length;\n int totalSum = Arrays.stream(nums).sum();\n int target = totalSum / n;\n boolean[] dp = new boolean[target + 1];\n dp[0] = true;\n for (int num : nums) {\n for (int i = target; i >= num; i--) {\n dp[i] = dp[i] || dp[i - num];\n }\n }\n for (int i = 1; i <= target; i++) {\n if (dp[i] && (totalSum - i) % n == 0) {\n return true;\n }\n }\n return false;\n }\n}", "import java.util.Arrays;\n\npublic class Solution {\n public boolean splitArraySameAverage(int[] nums) {\n int n = nums.length;\n int sum = Arrays.stream(nums).sum();\n int target = sum / 2;\n int[] prefixSum = new int[n + 1];\n for (int i = 1; i <= n; i++) {\n prefixSum[i] = prefixSum[i - 1] + nums[i - 1];\n }\n return dfs(nums, prefixSum, target, n, 0, 0);\n }\n\n private boolean dfs(int[] nums, int[] prefixSum, int target, int n, int start, int sum) {\n if (sum == target) {\n return true;\n }\n if (sum > target || start == n) {\n return false;\n }\n for (int i = start; i < n; i++) {\n if (dfs(nums, prefixSum, target, n, i + 1, sum + prefixSum[i + 1] - prefixSum[start])) {\n return true;\n }\n }\n return false;\n }\n}", "public boolean splitArraySameAverage(int[] nums) {\n int n = nums.length;\n int sum = 0;\n for (int num : nums) {\n sum += num;\n }\n int target = sum * 2 / n;\n int[] prefixSum = new int[n + 1];\n for (int i = 1; i <= n; i++) {\n prefixSum[i] = prefixSum[i - 1] + nums[i - 1];\n }\n for (int i = 1; i <= n; i++) {\n for (int j = i + 1; j <= n; j++) {\n if (prefixSum[j] - prefixSum[i] == target) {\n return true;\n }\n }\n }\n return false;\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public int minCostClimbingStairs(int[] cost)` to solve the following problem:\nGiven an integer array cost where cost[i] is the cost of ith step on a staircase,\nreturn the minimum cost to reach the top of the floor.\nYou can either start from the step with index 0 or the step with index 1.\n\nExample:\n>>> minCostClimbingStairs([10, 15, 20])\n15\nExplanation: You will start at index 1.\n- Pay 15 and climb two steps to reach the top.\nThe total cost is 15.\n\n>>> minCostClimbingStairs([1, 100, 1, 1, 1, 100, 1, 1, 100, 1])\n6\nExplanation: You will start at index 0.\n- Pay 1 and climb two steps to reach index 2.\n- Pay 1 and climb two steps to reach index 4.\n- Pay 1 and climb two steps to reach index 6.\n- Pay 1 and climb one step to reach index 7.\n- Pay 1 and climb two steps to reach index 9.\n- Pay 1 and climb one step to reach the top.\nThe total cost is 6.", "ground-truth": null, "prediction": [ "public int minCostClimbingStairs(int[] cost) {\n int[] dp = new int[cost.length + 1];\n dp[0] = 0;\n dp[1] = 0;\n for (int i = 2; i <= cost.length; i++) {\n dp[i] = Math.min(dp[i - 1] + cost[i - 1], dp[i - 2] + cost[i - 2]);\n }\n return dp[cost.length];\n}", "public int minCostClimbingStairs(int[] cost) {\n int n = cost.length;\n int[] dp = new int[n];\n dp[0] = cost[0];\n dp[1] = cost[1];\n for (int i = 2; i < n; i++) {\n dp[i] = cost[i] + Math.min(dp[i - 1], dp[i - 2]);\n }\n return Math.min(dp[n - 1], dp[n - 2]);\n}", "public int minCostClimbingStairs(int[] cost) {\n int[] dp = new int[cost.length + 1];\n dp[0] = 0;\n dp[1] = 0;\n\n for (int i = 2; i <= cost.length; i++) {\n dp[i] = Math.min(dp[i - 1] + cost[i - 1], dp[i - 2] + cost[i - 2]);\n }\n\n return dp[cost.length];\n}", "public int minCostClimbingStairs(int[] cost) {\n int[] dp = new int[cost.length + 1];\n dp[0] = 0;\n dp[1] = 0;\n\n for (int i = 2; i <= cost.length; i++) {\n dp[i] = Math.min(dp[i - 1] + cost[i - 1], dp[i - 2] + cost[i - 2]);\n }\n\n return dp[cost.length];\n}", "public int minCostClimbingStairs(int[] cost) {\n int n = cost.length;\n int[] dp = new int[n + 1];\n dp[0] = 0;\n dp[1] = 0;\n\n for (int i = 2; i <= n; i++) {\n dp[i] = Math.min(dp[i - 1] + cost[i - 1], dp[i - 2] + cost[i - 2]);\n }\n\n return dp[n];\n}" ], "moe_id": { "python": 0.0207, "cpp": 0.7694, "swift": 0.0005, "rust": 0.0079, "csharp": 0.002, "java": 0.0067, "php": 0.0, "typescript": 0.1927, "shell": 0.0 } }, { "source": "Write a Java function `public int uniqueMorseRepresentations(String[] words)` to solve the following problem:\nGiven an array of strings words where each word can be written as a concatenation of the Morse code of each letter,\nreturn the number of different transformations among all words.\n\nExample:\nuniqueMorseRepresentations([\"gin\",\"zen\",\"gig\",\"msg\"]) -> 2\nuniqueMorseRepresentations([\"a\"]) -> 1", "ground-truth": null, "prediction": [ "public int uniqueMorseRepresentations(String[] words) {\n String[] morse = {\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"};\n Set set = new HashSet<>();\n for (String word : words) {\n StringBuilder sb = new StringBuilder();\n for (char c : word.toCharArray()) {\n sb.append(morse[c - 'a']);\n }\n set.add(sb.toString());\n }\n return set.size();\n}", "public int uniqueMorseRepresentations(String[] words) {\n String[] morse = {\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"};\n Set set = new HashSet<>();\n for (String word : words) {\n StringBuilder sb = new StringBuilder();\n for (char c : word.toCharArray()) {\n sb.append(morse[c - 'a']);\n }\n set.add(sb.toString());\n }\n return set.size();\n}", "public int uniqueMorseRepresentations(String[] words) {\n String[] morseCode = {\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"};\n Set uniqueMorse = new HashSet<>();\n for (String word : words) {\n StringBuilder morse = new StringBuilder();\n for (char c : word.toCharArray()) {\n morse.append(morseCode[c - 'a']);\n }\n uniqueMorse.add(morse.toString());\n }\n return uniqueMorse.size();\n}", "public int uniqueMorseRepresentations(String[] words) {\n String[] morse = {\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"};\n Set set = new HashSet<>();\n for (String word : words) {\n StringBuilder sb = new StringBuilder();\n for (char c : word.toCharArray()) {\n sb.append(morse[c - 'a']);\n }\n set.add(sb.toString());\n }\n return set.size();\n}", "public int uniqueMorseRepresentations(String[] words) {\n String[] morse = {\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"};\n Set set = new HashSet<>();\n for (String word : words) {\n StringBuilder sb = new StringBuilder();\n for (char c : word.toCharArray()) {\n sb.append(morse[c - 'a']);\n }\n set.add(sb.toString());\n }\n return set.size();\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public boolean hasAllCodes(String s, int k)` to solve the following problem:\nGiven a binary string s and an integer k, return true if every binary string of length k is a substring of s, or false otherwise.\n\nExample 1:\nInput: s = \"00110110\", k = 2\nOutput: true\nExplanation: All binary strings of length 2 (\"00\", \"01\", \"10\", and \"11\") are substrings of s.\n\nExample 2:\nInput: s = \"0110\", k = 1\nOutput: true\nExplanation: All binary strings of length 1 (\"0\" and \"1\") are substrings of s.\n\nExample 3:\nInput: s = \"0110\", k = 2\nOutput: false\nExplanation: The binary string \"00\" is not a substring of s.", "ground-truth": null, "prediction": [ "public boolean hasAllCodes(String s, int k) {\n int n = s.length();\n int total = (1 << k);\n boolean[] seen = new boolean[total];\n int mask = (1 << k) - 1;\n int count = 0;\n int curr = 0;\n for (int i = 0; i < n; i++) {\n curr = ((curr << 1) & mask) | (s.charAt(i) - '0');\n if (i >= k - 1 && !seen[curr]) {\n seen[curr] = true;\n count++;\n if (count == total) {\n return true;\n }\n }\n }\n return false;\n}", "public boolean hasAllCodes(String s, int k) {\n int n = s.length();\n int total = (int) Math.pow(2, k);\n boolean[] seen = new boolean[total];\n int mask = (1 << k) - 1;\n int count = 0;\n int left = 0, right = 0;\n while (right < n) {\n while (right - left < k) {\n right++;\n }\n if (right - left == k) {\n int num = Integer.parseInt(s.substring(left, right), 2);\n if (num < total && !seen[num]) {\n seen[num] = true;\n count++;\n }\n left++;\n }\n }\n return count == total;\n}", "public boolean hasAllCodes(String s, int k) {\n int n = s.length();\n int mask = (1 << k) - 1;\n int count = 0;\n int current = 0;\n for (int i = 0; i < n; i++) {\n current = ((current << 1) & mask) | (s.charAt(i) - '0');\n if (i >= k - 1 && (current & (1 << (k - 1))) == 0) {\n count++;\n if (count == (1 << k)) {\n return true;\n }\n }\n }\n return false;\n}", "public boolean hasAllCodes(String s, int k) {\n int n = s.length();\n int total = (1 << k);\n boolean[] seen = new boolean[total];\n int mask = (1 << k) - 1;\n int current = 0;\n for (int i = 0; i < n; i++) {\n current = ((current << 1) & mask) | (s.charAt(i) - '0');\n if (i >= k - 1 && !seen[current]) {\n seen[current] = true;\n total--;\n if (total == 0) {\n return true;\n }\n }\n }\n return false;\n}", "public boolean hasAllCodes(String s, int k) {\n int n = s.length();\n int total = (int) Math.pow(2, k);\n boolean[] seen = new boolean[total];\n int mask = (1 << k) - 1;\n int count = 0;\n int left = 0, right = 0;\n while (right < n) {\n if (right - left + 1 <= k) {\n int num = Integer.parseInt(s.substring(left, right + 1), 2);\n if ((num & mask) == num) {\n seen[num] = true;\n count++;\n }\n right++;\n } else {\n int num = Integer.parseInt(s.substring(left, right + 1), 2);\n if ((num & mask) == num) {\n seen[num] = true;\n count++;\n }\n left++;\n right++;\n }\n }\n return count == total;\n}" ], "moe_id": { "python": 0.0069, "cpp": 0.9861, "swift": 0.0, "rust": 0.0016, "csharp": 0.0004, "java": 0.0047, "php": 0.0, "typescript": 0.0002, "shell": 0.0 } }, { "source": "Write a Java function `public int isPrefixOfWord(String sentence, String searchWord)` to solve the following problem:\nCheck if the searchWord is a prefix of any word in the sentence.\nIf searchWord is a prefix of multiple words, return the index of the first matching word.\nIf searchWord is not a prefix of any word, return -1.\n\nExample:\n>>> isPrefixOfWord(\"i love eating burger\", \"burg\")\n4\n>>> isPrefixOfWord(\"this problem is an easy problem\", \"pro\")\n2\n>>> isPrefixOfWord(\"i am tired\", \"you\")\n-1", "ground-truth": null, "prediction": [ "public int isPrefixOfWord(String sentence, String searchWord) {\n String[] words = sentence.split(\" \");\n for (int i = 0; i < words.length; i++) {\n if (words[i].startsWith(searchWord)) {\n return i + 1;\n }\n }\n return -1;\n}", "public int isPrefixOfWord(String sentence, String searchWord) {\n String[] words = sentence.split(\" \");\n for (int i = 0; i < words.length; i++) {\n if (words[i].startsWith(searchWord)) {\n return i + 1;\n }\n }\n return -1;\n}", "public int isPrefixOfWord(String sentence, String searchWord) {\n String[] words = sentence.split(\" \");\n for (int i = 0; i < words.length; i++) {\n if (words[i].startsWith(searchWord)) {\n return i + 1;\n }\n }\n return -1;\n}", "public int isPrefixOfWord(String sentence, String searchWord) {\n String[] words = sentence.split(\" \");\n for (int i = 0; i < words.length; i++) {\n if (words[i].startsWith(searchWord)) {\n return i + 1;\n }\n }\n return -1;\n}", "public int isPrefixOfWord(String sentence, String searchWord) {\n String[] words = sentence.split(\" \");\n for (int i = 0; i < words.length; i++) {\n if (words[i].startsWith(searchWord)) {\n return i + 1;\n }\n }\n return -1;\n}" ], "moe_id": { "python": 0.0343, "cpp": 0.0095, "swift": 0.2289, "rust": 0.1909, "csharp": 0.0909, "java": 0.0376, "php": 0.0151, "typescript": 0.3927, "shell": 0.0 } }, { "source": "Write a Java function `public int minInsertions(String s)` to solve the following problem:\nGiven a string s composed of '(' and ')', the left and right brackets in s may be unbalanced. Each operation can insert a '(' or ')', and calculate the minimum number of insertion operations required. Make the left and right brackets in s balanced.\n\nExample 1:\nInput: s = \"(()))\"\nOutput: 1\nExplanation: We need to add one '(' at the first of the string to make it balanced: \"((()))\".\nExample 2:\nInput: s = \"((()))\"\nOutput: 0\n\n- s consists of '(' and ')' only.", "ground-truth": null, "prediction": [ "public int minInsertions(String s) {\n int left = 0, right = 0;\n for (int i = 0; i < s.length(); i++) {\n if (s.charAt(i) == '(') {\n left++;\n } else {\n if (left > 0) {\n left--;\n } else {\n right++;\n }\n }\n }\n return left + right;\n}", "public int minInsertions(String s) {\n int left = 0, right = 0;\n for (int i = 0; i < s.length(); i++) {\n if (s.charAt(i) == '(') {\n left++;\n } else {\n if (left > 0) {\n left--;\n } else {\n right++;\n }\n }\n }\n return left + right;\n}", "public int minInsertions(String s) {\n int left = 0, right = 0;\n for (int i = 0; i < s.length(); i++) {\n if (s.charAt(i) == '(') {\n left++;\n } else {\n if (left > 0) {\n left--;\n } else {\n right++;\n }\n }\n }\n return left + right;\n}", "public int minInsertions(String s) {\n int left = 0, right = 0;\n for (char c : s.toCharArray()) {\n if (c == '(') {\n left++;\n } else {\n if (left > 0) {\n left--;\n } else {\n right++;\n }\n }\n }\n return left + right;\n}", "public int minInsertions(String s) {\n int left = 0, right = 0;\n for (char c : s.toCharArray()) {\n if (c == '(') {\n left++;\n } else {\n if (left > 0) {\n left--;\n } else {\n right++;\n }\n }\n }\n return left + right;\n}" ], "moe_id": { "python": 0.5951, "cpp": 0.0001, "swift": 0.0097, "rust": 0.1435, "csharp": 0.0374, "java": 0.1087, "php": 0.0013, "typescript": 0.1041, "shell": 0.0 } }, { "source": "Write a Java function `public int minOperations(int n)` to solve the following problem:\nGiven an integer n, return the minimum number of operations required to make all elements in the array arr equal.\nThe array arr has a length of n, and arr[i] = (2 * i) + 1 for 0 <= i < n.\nIn one operation, you can select two indices x and y (0 <= x, y < n) and subtract 1 from arr[x] and add 1 to arr[y] (i.e., arr[x] -= 1 and arr[y] += 1).\nThe goal is to make all elements in arr equal. The test cases will ensure that after performing some operations, all elements in arr can be made equal.\n\nExample 1:\nInput: n = 3\nOutput: 2\nExplanation: arr = [1, 3, 5]\nFirst operation: x = 2, y = 0 -> arr = [2, 3, 4]\nSecond operation: x = 2, y = 0 -> arr = [3, 3, 3]\n\nExample 2:\nInput: n = 6\nOutput: 9", "ground-truth": null, "prediction": [ "public int minOperations(int n) {\n int[] arr = new int[n];\n for (int i = 0; i < n; i++) {\n arr[i] = (2 * i) + 1;\n }\n int count = 0;\n for (int i = 0; i < n / 2; i++) {\n if (arr[i] != arr[n - i - 1]) {\n count += Math.abs(arr[i] - arr[n - i - 1]);\n }\n }\n return count;\n}", "public int minOperations(int n) {\n int sum = 0;\n for (int i = 0; i < n; i++) {\n sum += (2 * i) + 1;\n }\n int avg = sum / n;\n int operations = 0;\n for (int i = 0; i < n; i++) {\n operations += Math.abs((2 * i) + 1 - avg);\n }\n return operations;\n}", "public int minOperations(int n) {\n int sum = 0;\n for (int i = 0; i < n; i++) {\n sum += (2 * i) + 1;\n }\n return sum / n;\n}", "public int minOperations(int n) {\n int sum = 0;\n for (int i = 0; i < n; i++) {\n sum += (2 * i) + 1;\n }\n int avg = sum / n;\n int operations = 0;\n for (int i = 0; i < n; i++) {\n operations += Math.abs((2 * i) + 1 - avg);\n }\n return operations;\n}", "public int minOperations(int n) {\n int sum = 0;\n for (int i = 0; i < n; i++) {\n sum += (2 * i) + 1;\n }\n int avg = sum / n;\n int count = 0;\n for (int i = 0; i < n; i++) {\n count += Math.abs((2 * i) + 1 - avg);\n }\n return count;\n}" ], "moe_id": { "python": 0.0, "cpp": 0.9986, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0013, "shell": 0.0 } }, { "source": "Write a Java function `public int highestAltitude(int[] gain)` to solve the following problem:\nGiven an integer array `gain` representing the net gain in altitude between consecutive points, return the highest altitude reached.\n\nExample:\n>>> highestAltitude([-5,1,5,0,-7])\n1\nExplanation: The altitudes are [0,-5,-4,1,1,-6]. The highest altitude reached is 1.\n\n>>> highestAltitude([-4,-3,-2,-1,4,3,2])\n0\nExplanation: The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest altitude reached is 0.\n\nConstraints:\n- The length of the `gain` array is between 1 and 100, inclusive.\n- Each element in the `gain` array is between -100 and 100, inclusive.", "ground-truth": null, "prediction": [ "public int highestAltitude(int[] gain) {\n int maxAltitude = 0;\n int currentAltitude = 0;\n for (int altitude : gain) {\n currentAltitude += altitude;\n maxAltitude = Math.max(maxAltitude, currentAltitude);\n }\n return maxAltitude;\n}", "public int highestAltitude(int[] gain) {\n int maxAltitude = 0;\n int currentAltitude = 0;\n for (int altitudeChange : gain) {\n currentAltitude += altitudeChange;\n maxAltitude = Math.max(maxAltitude, currentAltitude);\n }\n return maxAltitude;\n}", "public int highestAltitude(int[] gain) {\n int max = 0;\n int altitude = 0;\n for (int i = 0; i < gain.length; i++) {\n altitude += gain[i];\n if (altitude > max) {\n max = altitude;\n }\n }\n return max;\n}", "public int highestAltitude(int[] gain) {\n int maxAltitude = 0;\n int currentAltitude = 0;\n for (int g : gain) {\n currentAltitude += g;\n maxAltitude = Math.max(maxAltitude, currentAltitude);\n }\n return maxAltitude;\n}", "public int highestAltitude(int[] gain) {\n int maxAltitude = 0;\n int currentAltitude = 0;\n for (int altitude : gain) {\n currentAltitude += altitude;\n maxAltitude = Math.max(maxAltitude, currentAltitude);\n }\n return maxAltitude;\n}" ], "moe_id": { "python": 0.0001, "cpp": 0.9998, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0001, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public int maxAbsoluteSum(int[] nums)` to solve the following problem:\nGiven an integer array nums, return the maximum absolute sum of any subarray.\n\n>>> maxAbsoluteSum(new int[]{1,-3,2,3,-4})\n5\n\n>>> maxAbsoluteSum(new int[]{2,-5,1,-4,3,-2})\n8", "ground-truth": null, "prediction": [ "public int maxAbsoluteSum(int[] nums) {\n int maxSum = 0, minSum = 0, maxAbsSum = 0;\n for (int num : nums) {\n maxSum = Math.max(0, maxSum + num);\n minSum = Math.min(0, minSum + num);\n maxAbsSum = Math.max(maxAbsSum, Math.abs(maxSum));\n maxAbsSum = Math.max(maxAbsSum, Math.abs(minSum));\n }\n return maxAbsSum;\n}", "public int maxAbsoluteSum(int[] nums) {\n int maxSum = 0, minSum = 0, maxAbsSum = 0;\n for (int num : nums) {\n maxSum = Math.max(0, maxSum + num);\n minSum = Math.min(0, minSum + num);\n maxAbsSum = Math.max(maxAbsSum, Math.abs(maxSum));\n maxAbsSum = Math.max(maxAbsSum, Math.abs(minSum));\n }\n return maxAbsSum;\n}", "public int maxAbsoluteSum(int[] nums) {\n int maxSum = 0;\n int minSum = 0;\n int maxAbsoluteSum = 0;\n int currentSum = 0;\n\n for (int num : nums) {\n currentSum += num;\n maxSum = Math.max(maxSum, currentSum);\n minSum = Math.min(minSum, currentSum);\n maxAbsoluteSum = Math.max(maxAbsoluteSum, Math.abs(maxSum - minSum));\n }\n\n return maxAbsoluteSum;\n}", "public int maxAbsoluteSum(int[] nums) {\n int maxSum = 0, minSum = 0, maxAbsSum = 0;\n for (int num : nums) {\n maxSum = Math.max(0, maxSum + num);\n minSum = Math.min(0, minSum + num);\n maxAbsSum = Math.max(maxAbsSum, Math.abs(maxSum));\n maxAbsSum = Math.max(maxAbsSum, Math.abs(minSum));\n }\n return maxAbsSum;\n}", "public int maxAbsoluteSum(int[] nums) {\n int maxSum = 0, minSum = 0, maxAbsSum = 0;\n for (int num : nums) {\n maxSum = Math.max(num, maxSum + num);\n minSum = Math.min(num, minSum + num);\n maxAbsSum = Math.max(maxAbsSum, Math.abs(maxSum), Math.abs(minSum));\n }\n return maxAbsSum;\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public int findMinFibonacciNumbers(int k)` to solve the following problem:\nGiven an integer k, return the minimum number of Fibonacci numbers whose sum is equal to k.\nFibonacci numbers are defined as follows:\nF1 = 1\nF2 = 1\nFn = Fn-1 + Fn-2, for n > 2.\nIt is guaranteed that there is at least one valid solution for the given k.\n\nExample 1:\nInput: k = 7\nOutput: 2\nExplanation: Fibonacci numbers are: 1, 1, 2, 3, 5, 8, 13, ...\nFor k = 7, we can get 2 + 5 = 7.\n\nExample 2:\nInput: k = 10\nOutput: 2\nExplanation: For k = 10, we can get 2 + 8 = 10.\n\nExample 3:\nInput: k = 19\nOutput: 3\nExplanation: For k = 19, we can get 1 + 5 + 13 = 19.", "ground-truth": null, "prediction": [ "public int findMinFibonacciNumbers(int k) {\n int[] fib = new int[100];\n fib[0] = 1;\n fib[1] = 1;\n for (int i = 2; i < 100; i++) {\n fib[i] = fib[i - 1] + fib[i - 2];\n }\n int count = 0;\n for (int i = 99; i >= 0; i--) {\n while (k >= fib[i]) {\n k -= fib[i];\n count++;\n }\n if (k == 0) {\n break;\n }\n }\n return count;\n}", "public int findMinFibonacciNumbers(int k) {\n int[] fib = new int[100];\n fib[0] = 1;\n fib[1] = 1;\n for (int i = 2; i < 100; i++) {\n fib[i] = fib[i - 1] + fib[i - 2];\n }\n int count = 0;\n for (int i = 99; i >= 0; i--) {\n while (k >= fib[i]) {\n k -= fib[i];\n count++;\n }\n if (k == 0) {\n break;\n }\n }\n return count;\n}", "public int findMinFibonacciNumbers(int k) {\n int[] fib = new int[100];\n fib[0] = 1;\n fib[1] = 1;\n for (int i = 2; i < 100; i++) {\n fib[i] = fib[i - 1] + fib[i - 2];\n }\n int count = 0;\n for (int i = 99; i >= 0; i--) {\n if (k >= fib[i]) {\n count++;\n k -= fib[i];\n }\n }\n return count;\n}", "public int findMinFibonacciNumbers(int k) {\n int[] fib = new int[100];\n fib[0] = 1;\n fib[1] = 1;\n for (int i = 2; i < 100; i++) {\n fib[i] = fib[i - 1] + fib[i - 2];\n }\n int count = 0;\n for (int i = 99; i >= 0; i--) {\n while (k >= fib[i]) {\n k -= fib[i];\n count++;\n }\n if (k == 0) {\n break;\n }\n }\n return count;\n}", "public int findMinFibonacciNumbers(int k) {\n int[] fib = {1, 1};\n int i = 2;\n while (fib[i - 1] + fib[i - 2] <= k) {\n fib[i] = fib[i - 1] + fib[i - 2];\n i++;\n }\n int count = 0;\n for (int j = i - 1; j >= 0 && k > 0; j--) {\n while (k >= fib[j]) {\n k -= fib[j];\n count++;\n }\n }\n return count;\n}" ], "moe_id": { "python": 0.0, "cpp": 0.9868, "swift": 0.0, "rust": 0.0002, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.013, "shell": 0.0 } }, { "source": "Write a Java function `public int kthFactor(int n, int k)` to solve the following problem:\nGiven two positive integers n and k, find the kth factor of n.\nA factor of n is a positive integer that divides n evenly.\nReturn the kth factor in ascending order. If n has less than k factors, return -1.\n\nExample 1:\nInput: n = 12, k = 3\nOutput: 3\nExplanation: The factors of 12 are [1, 2, 3, 4, 6, 12]. The 3rd factor is 3.\n\nExample 2:\nInput: n = 7, k = 2\nOutput: 7\nExplanation: The factors of 7 are [1, 7]. The 2nd factor is 7.\n\nExample 3:\nInput: n = 4, k = 4\nOutput: -1\nExplanation: The factors of 4 are [1, 2, 4]. There is no 4th factor, so we return -1.", "ground-truth": null, "prediction": [ "public int kthFactor(int n, int k) {\n int count = 0;\n for (int i = 1; i <= n; i++) {\n if (n % i == 0) {\n count++;\n if (count == k) {\n return i;\n }\n }\n }\n return -1;\n}", "public int kthFactor(int n, int k) {\n int count = 0;\n for (int i = 1; i <= n; i++) {\n if (n % i == 0) {\n count++;\n if (count == k) {\n return i;\n }\n }\n }\n return -1;\n}", "public int kthFactor(int n, int k) {\n int count = 0;\n for (int i = 1; i <= n; i++) {\n if (n % i == 0) {\n count++;\n if (count == k) {\n return i;\n }\n }\n }\n return -1;\n}", "public int kthFactor(int n, int k) {\n int count = 0;\n for (int i = 1; i <= n; i++) {\n if (n % i == 0) {\n count++;\n if (count == k) {\n return i;\n }\n }\n }\n return -1;\n}", "public int kthFactor(int n, int k) {\n int count = 0;\n for (int i = 1; i <= n; i++) {\n if (n % i == 0) {\n count++;\n if (count == k) {\n return i;\n }\n }\n }\n return -1;\n}" ], "moe_id": { "python": 0.0022, "cpp": 0.9273, "swift": 0.0, "rust": 0.0084, "csharp": 0.0, "java": 0.0018, "php": 0.0, "typescript": 0.0603, "shell": 0.0 } }, { "source": "Write a Java function `public String makeGood(String s)` to solve the following problem:\nGiven a string s consisting of lowercase and uppercase English letters,\nyou need to make the string \"good\".\nA string is considered \"good\" if there are no adjacent characters such that\none is a lowercase letter and the other is the corresponding uppercase letter.\nYou can choose any adjacent characters in the string and remove them until the string is \"good\".\nReturn the final \"good\" string.\n\nExample 1:\nInput: s = \"leEeetcode\"\nOutput: \"leetcode\"\nExplanation: You can remove \"Ee\" to make \"leetcode\".\n\nExample 2:\nInput: s = \"abBAcC\"\nOutput: \"\"\nExplanation: There are multiple possible solutions, such as:\n- Remove \"bB\" to make \"aAcC\", then remove \"cC\" to make \"aA\", then remove \"aA\" to make \"\".\n- Remove \"aA\" to make \"abBAcC\", then remove \"bB\" to make \"aAcC\", then remove \"cC\" to make \"aA\",\nthen remove \"aA\" to make \"\".\nNo matter the choices, the result is an empty string.\n\nExample 3:\nInput: s = \"s\"\nOutput: \"s\"\nExplanation: The string is already \"good\".", "ground-truth": null, "prediction": [ "public String makeGood(String s) {\n StringBuilder sb = new StringBuilder();\n for (char c : s.toCharArray()) {\n if (sb.length() > 0 && Math.abs(sb.charAt(sb.length() - 1) - c) == 32) {\n sb.deleteCharAt(sb.length() - 1);\n } else {\n sb.append(c);\n }\n }\n return sb.toString();\n}", "public String makeGood(String s) {\n StringBuilder sb = new StringBuilder();\n for (char c : s.toCharArray()) {\n if (sb.length() > 0 && Math.abs(sb.charAt(sb.length() - 1) - c) == 32) {\n sb.deleteCharAt(sb.length() - 1);\n } else {\n sb.append(c);\n }\n }\n return sb.toString();\n}", "public String makeGood(String s) {\n StringBuilder sb = new StringBuilder();\n for (char c : s.toCharArray()) {\n if (sb.length() > 0 && Math.abs(sb.charAt(sb.length() - 1) - c) == 32) {\n sb.deleteCharAt(sb.length() - 1);\n } else {\n sb.append(c);\n }\n }\n return sb.toString();\n}", "public String makeGood(String s) {\n StringBuilder sb = new StringBuilder();\n for (char c : s.toCharArray()) {\n if (sb.length() > 0 && Math.abs(sb.charAt(sb.length() - 1) - c) == 32) {\n sb.deleteCharAt(sb.length() - 1);\n } else {\n sb.append(c);\n }\n }\n return sb.toString();\n}", "public String makeGood(String s) {\n StringBuilder sb = new StringBuilder();\n for (char c : s.toCharArray()) {\n if (sb.length() > 0 && Math.abs(c - sb.charAt(sb.length() - 1)) == 32) {\n sb.deleteCharAt(sb.length() - 1);\n } else {\n sb.append(c);\n }\n }\n return sb.toString();\n}" ], "moe_id": { "python": 0.0271, "cpp": 0.7951, "swift": 0.0007, "rust": 0.0312, "csharp": 0.0053, "java": 0.0248, "php": 0.0001, "typescript": 0.1158, "shell": 0.0 } }, { "source": "Write a Java function `public int maxUniqueSplit(String s)` to solve the following problem:\nGiven a string s, split the string and return the maximum number of unique substrings.\nThe split substrings should be able to reconstruct the original string, and each substring must be unique.\n\nExample:\nInput: s = \"ababccc\"\nOutput: 5\nExplanation: One possible way to split the string is ['a', 'b', 'ab', 'c', 'cc'].\nSplitting the string as ['a', 'b', 'a', 'b', 'c', 'cc'] is not valid, because both 'a' and 'b' appear more than once.\n\nNote:\n- The length of s is between 1 and 16.\n- s only contains lowercase English letters.", "ground-truth": null, "prediction": [ "public int maxUniqueSplit(String s) {\n int maxUnique = 0;\n Set uniqueSubstrings = new HashSet<>();\n\n for (int i = 1; i <= s.length(); i++) {\n String substring = s.substring(0, i);\n if (!uniqueSubstrings.contains(substring)) {\n uniqueSubstrings.add(substring);\n maxUnique++;\n }\n if (uniqueSubstrings.size() == s.length()) {\n break;\n }\n }\n\n return maxUnique;\n}", "public int maxUniqueSplit(String s) {\n int maxUnique = 0;\n Set uniqueSubstrings = new HashSet<>();\n helper(s, 0, uniqueSubstrings, maxUnique);\n return maxUnique;\n}\n\nprivate void helper(String s, int start, Set uniqueSubstrings, int maxUnique) {\n if (start == s.length()) {\n maxUnique = Math.max(maxUnique, uniqueSubstrings.size());\n return;\n }\n for (int i = start; i < s.length(); i++) {\n String sub = s.substring(start, i + 1);\n if (!uniqueSubstrings.contains(sub)) {\n uniqueSubstrings.add(sub);\n helper(s, i + 1, uniqueSubstrings, maxUnique);\n uniqueSubstrings.remove(sub);\n }\n }\n}", "public int maxUniqueSplit(String s) {\n int maxUnique = 0;\n Set uniqueSubstrings = new HashSet<>();\n for (int i = 1; i <= s.length(); i++) {\n String substring = s.substring(0, i);\n if (!uniqueSubstrings.contains(substring)) {\n uniqueSubstrings.add(substring);\n maxUnique++;\n }\n if (uniqueSubstrings.size() == s.length()) {\n break;\n }\n }\n return maxUnique;\n}", "public int maxUniqueSplit(String s) {\n int maxUnique = 0;\n Set uniqueSubstrings = new HashSet<>();\n\n for (int i = 1; i <= s.length(); i++) {\n String substring = s.substring(0, i);\n if (!uniqueSubstrings.contains(substring)) {\n uniqueSubstrings.add(substring);\n maxUnique++;\n }\n if (uniqueSubstrings.size() == s.length()) {\n break;\n }\n }\n\n return maxUnique;\n}", "public int maxUniqueSplit(String s) {\n int maxUnique = 0;\n Set uniqueSubstrings = new HashSet<>();\n backtrack(s, 0, uniqueSubstrings, maxUnique);\n return maxUnique;\n}\n\nprivate void backtrack(String s, int start, Set uniqueSubstrings, int maxUnique) {\n if (start == s.length()) {\n maxUnique = Math.max(maxUnique, uniqueSubstrings.size());\n return;\n }\n for (int i = start; i < s.length(); i++) {\n String substring = s.substring(start, i + 1);\n if (!uniqueSubstrings.contains(substring)) {\n uniqueSubstrings.add(substring);\n backtrack(s, i + 1, uniqueSubstrings, maxUnique);\n uniqueSubstrings.remove(substring);\n }\n }\n}" ], "moe_id": { "python": 0.0, "cpp": 0.9999, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0001, "shell": 0.0 } }, { "source": "Write a Java function `public int minOperations(String[] logs)` to solve the following problem:\nGiven a list of logs representing folder operations,\nreturn the minimum number of steps required to return to the main folder.\n\nExample:\nInput: logs = [\"d1/\",\"d2/\",\"../\",\"d21/\",\"./\"]\nOutput: 2\nExplanation: Perform the \"../\" operation twice to return to the main folder.\n\nInput: logs = [\"d1/\",\"d2/\",\"./\",\"d3/\",\"../\",\"d31/\"]\nOutput: 3\n\nInput: logs = [\"d1/\",\"../\",\"../\",\"../\"]\nOutput: 0", "ground-truth": null, "prediction": [ "public int minOperations(String[] logs) {\n int steps = 0;\n for (String log : logs) {\n if (log.equals(\"./\")) {\n continue;\n } else if (log.equals(\"../\")) {\n if (steps > 0) {\n steps--;\n }\n } else {\n steps++;\n }\n }\n return steps;\n}", "public int minOperations(String[] logs) {\n int steps = 0;\n for (String log : logs) {\n if (log.equals(\"./\")) {\n continue;\n } else if (log.equals(\"../\")) {\n if (steps > 0) {\n steps--;\n }\n } else {\n steps++;\n }\n }\n return steps;\n}", "public int minOperations(String[] logs) {\n int steps = 0;\n for (String log : logs) {\n if (log.equals(\"./\")) {\n continue;\n } else if (log.equals(\"../\")) {\n if (steps > 0) {\n steps--;\n }\n } else {\n steps++;\n }\n }\n return steps;\n}", "public int minOperations(String[] logs) {\n int steps = 0;\n for (String log : logs) {\n if (log.equals(\"./\")) {\n continue;\n } else if (log.equals(\"../\")) {\n if (steps > 0) {\n steps--;\n }\n } else {\n steps++;\n }\n }\n return steps;\n}", "public int minOperations(String[] logs) {\n int steps = 0;\n for (String log : logs) {\n if (log.equals(\"./\")) {\n continue;\n } else if (log.equals(\"../\")) {\n if (steps > 0) {\n steps--;\n }\n } else {\n steps++;\n }\n }\n return steps;\n}" ], "moe_id": { "python": 0.2321, "cpp": 0.0, "swift": 0.0007, "rust": 0.0872, "csharp": 0.0194, "java": 0.1544, "php": 0.0006, "typescript": 0.5057, "shell": 0.0 } }, { "source": "Write a Java function `public String getSmallestString(int n, int k)` to solve the following problem:\nReturn the lexicographically smallest string of length n and value k.\nThe value of a string is the sum of the positions of its characters in the alphabet (starting from 1).\nExample:\n>>> getSmallestString(3, 27)\n\"aay\"\n>>> getSmallestString(5, 73)\n\"aaszz\"", "ground-truth": null, "prediction": [ "public String getSmallestString(int n, int k) {\n StringBuilder result = new StringBuilder();\n for (int i = 25; i >= 0; i--) {\n int max = Math.min(k - n + 1, 26);\n result.append((char) ('a' + max - 1));\n k -= max;\n n--;\n }\n return result.toString();\n}", "public String getSmallestString(int n, int k) {\n StringBuilder result = new StringBuilder();\n int[] alphabet = new int[26];\n for (int i = 0; i < 26; i++) {\n alphabet[i] = i + 1;\n }\n for (int i = 0; i < n; i++) {\n int min = 1;\n for (int j = 0; j < 26; j++) {\n if (alphabet[j] + min <= k) {\n min = alphabet[j];\n }\n }\n result.append((char) ('a' + min - 1));\n k -= min;\n alphabet[min - 1] = 0;\n }\n return result.toString();\n}", "public String getSmallestString(int n, int k) {\n StringBuilder result = new StringBuilder();\n for (int i = 25; i >= 0; i--) {\n int count = Math.min(k - i, 26 - i);\n result.append((char) ('a' + count));\n k -= count;\n }\n return result.toString();\n}", "public String getSmallestString(int n, int k) {\n StringBuilder result = new StringBuilder();\n for (int i = n; i > 0; i--) {\n int maxChar = (k - i + 1) % 26;\n result.append((char) ('a' + maxChar - 1));\n k -= maxChar;\n }\n return result.reverse().toString();\n}", "public String getSmallestString(int n, int k) {\n StringBuilder result = new StringBuilder();\n for (int i = 25; i >= 0; i--) {\n int max = Math.min(k - (n - 1), 26);\n result.append((char) ('a' + max));\n k -= max;\n n--;\n }\n return result.toString();\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static double calculateProbability(int n)` to solve the following problem:\nGiven the number of passengers n, calculate the probability that the last passenger will sit in their own seat.\n @param n The number of passengers.\n @return The probability that the last passenger will sit in their own seat.\n\n Example 1:\n Input: n = 1\n Output: 1.00000\n\n Example 2:\n Input: n = 2\n Output: 0.50000\n\n Example 3:\n Input: n = 3\n Output: 0.50000\n\n Example 4:\n Input: n = 4\n Output: 0.50000\n\n Example 5:\n Input: n = 5\n Output: 0.50000\n\n Example 6:\n Input: n = 100000\n Output: 0.50000", "ground-truth": null, "prediction": [ "public static double calculateProbability(int n) {\n if (n <= 2) {\n return 1.0;\n }\n double probability = 0.0;\n for (int i = 1; i <= n; i++) {\n probability += (double) i / n;\n }\n return probability;\n}", "public static double calculateProbability(int n) {\n if (n <= 1) {\n return 1.0;\n }\n return 0.5;\n}", "public static double calculateProbability(int n) {\n if (n <= 2) {\n return 1.0;\n }\n return 0.5;\n}", "public static double calculateProbability(int n) {\n if (n <= 1) {\n return 1.0;\n }\n double probability = 0.5;\n for (int i = 2; i <= n; i++) {\n probability *= (i - 1) / i;\n }\n return probability;\n}", "public static double calculateProbability(int n) {\n if (n <= 1) {\n return 1.0;\n }\n double probability = 0.5;\n for (int i = 2; i <= n; i++) {\n probability *= 2;\n }\n return probability;\n}" ], "moe_id": { "python": 0.024, "cpp": 0.684, "swift": 0.0, "rust": 0.0368, "csharp": 0.0003, "java": 0.0656, "php": 0.0, "typescript": 0.1893, "shell": 0.0 } }, { "source": "Write a Java function `public static int singleNumber(int[] nums)` to solve the following problem:\nGiven an integer array nums where every element appears three times except for one, which appears only once. Find and return the element that appears only once.\n\n @param nums An integer array where every element appears three times except for one.\n @return The element that appears only once.\n\n Example:\n singleNumber(new int[]{2,2,3,2})\n Output: 3\n\n Example:\n singleNumber(new int[]{0,1,0,1,0,1,99})\n Output: 99", "ground-truth": null, "prediction": [ "public static int singleNumber(int[] nums) {\n int ones = 0, twos = 0;\n for (int num : nums) {\n ones = (ones ^ num) & ~twos;\n twos = (twos ^ num) & ~ones;\n }\n return ones;\n}", "public static int singleNumber(int[] nums) {\n int ones = 0, twos = 0;\n for (int num : nums) {\n ones = (ones ^ num) & ~twos;\n twos = (twos ^ num) & ~ones;\n }\n return ones;\n}", "public static int singleNumber(int[] nums) {\n int ones = 0, twos = 0;\n for (int num : nums) {\n ones = (ones ^ num) & ~twos;\n twos = (twos ^ num) & ~ones;\n }\n return ones;\n}", "public static int singleNumber(int[] nums) {\n int ones = 0, twos = 0;\n for (int num : nums) {\n ones = (ones ^ num) & ~twos;\n twos = (twos ^ num) & ~ones;\n }\n return ones;\n}", "public static int singleNumber(int[] nums) {\n int ones = 0, twos = 0;\n for (int num : nums) {\n ones = (ones ^ num) & ~twos;\n twos = (twos ^ num) & ~ones;\n }\n return ones;\n}" ], "moe_id": { "python": 0.0097, "cpp": 0.8077, "swift": 0.124, "rust": 0.0366, "csharp": 0.0077, "java": 0.0034, "php": 0.0003, "typescript": 0.0108, "shell": 0.0 } }, { "source": "Write a Java function `public static List findSteppingNumbers(int low, int high)` to solve the following problem:\nFind all stepping numbers in the range [low, high] where a stepping number is defined as a number where each digit is either one more or one less than the adjacent digit.\n\n@param low The lower bound of the range.\n@param high The upper bound of the range.\n@return A list of stepping numbers within the range [low, high] sorted in ascending order.\n\nExample:\nfindSteppingNumbers(0, 21)\nOutput: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 21]", "ground-truth": null, "prediction": [ "import java.util.ArrayList;\nimport java.util.List;\n\npublic class SteppingNumbers {\n public static List findSteppingNumbers(int low, int high) {\n List result = new ArrayList<>();\n for (int i = 0; i <= 9; i++) {\n if (i >= low && i <= high) {\n result.add(i);\n }\n findSteppingNumbersHelper(i, low, high, result);\n }\n result.sort(null);\n return result;\n }\n\n private static void findSteppingNumbersHelper(int num, int low, int high, List result) {\n if (num >= low && num <= high) {\n result.add(num);\n }\n if (num % 10 != 0 && num % 10 - 1 >= low && num % 10 - 1 <= high) {\n findSteppingNumbersHelper(num * 10 + (num % 10 - 1), low, high, result);\n }\n if (num % 10 != 9 && num % 10 + 1 >= low && num % 10 + 1 <= high) {\n findSteppingNumbersHelper(num * 10 + (num % 10 + 1), low, high, result);\n }\n }\n\n public static void main(String[] args) {\n System.out.println(findSteppingNumbers(0, 21));\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class SteppingNumbers {\n\n public static List findSteppingNumbers(int low, int high) {\n List result = new ArrayList<>();\n for (int i = 0; i <= 9; i++) {\n if (i >= low && i <= high) {\n result.add(i);\n }\n findSteppingNumbersHelper(i, low, high, result);\n }\n result.sort(null);\n return result;\n }\n\n private static void findSteppingNumbersHelper(int num, int low, int high, List result) {\n if (num >= low && num <= high) {\n result.add(num);\n }\n int lastDigit = num % 10;\n if (lastDigit > 0) {\n int newNum = num * 10 + (lastDigit - 1);\n if (newNum <= high) {\n findSteppingNumbersHelper(newNum, low, high, result);\n }\n }\n if (lastDigit < 9) {\n int newNum = num * 10 + (lastDigit + 1);\n if (newNum <= high) {\n findSteppingNumbersHelper(newNum, low, high, result);\n }\n }\n }\n\n public static void main(String[] args) {\n System.out.println(findSteppingNumbers(0, 21)); // Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 21]\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class SteppingNumberFinder {\n\n public static List findSteppingNumbers(int low, int high) {\n List steppingNumbers = new ArrayList<>();\n for (int i = 0; i <= 9; i++) {\n if (i >= low && i <= high) {\n steppingNumbers.add(i);\n }\n findSteppingNumbersHelper(i, steppingNumbers, low, high);\n }\n steppingNumbers.sort(null);\n return steppingNumbers;\n }\n\n private static void findSteppingNumbersHelper(int num, List steppingNumbers, int low, int high) {\n if (num >= low && num <= high) {\n steppingNumbers.add(num);\n }\n int lastDigit = num % 10;\n if (lastDigit != 0) {\n int newNum = num * 10 + (lastDigit - 1);\n if (newNum >= low && newNum <= high) {\n steppingNumbers.add(newNum);\n }\n findSteppingNumbersHelper(newNum, steppingNumbers, low, high);\n }\n if (lastDigit != 9) {\n int newNum = num * 10 + (lastDigit + 1);\n if (newNum >= low && newNum <= high) {\n steppingNumbers.add(newNum);\n }\n findSteppingNumbersHelper(newNum, steppingNumbers, low, high);\n }\n }\n\n public static void main(String[] args) {\n List result = findSteppingNumbers(0, 21);\n System.out.println(result);\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class SteppingNumberFinder {\n\n public static List findSteppingNumbers(int low, int high) {\n List result = new ArrayList<>();\n for (int i = 0; i <= 9; i++) {\n if (i >= low && i <= high) {\n result.add(i);\n }\n findSteppingNumbersHelper(i, low, high, result);\n }\n result.sort(null);\n return result;\n }\n\n private static void findSteppingNumbersHelper(int num, int low, int high, List result) {\n if (num >= low && num <= high) {\n result.add(num);\n }\n if (num % 10 != 0) {\n int nextNum = num * 10 + (num % 10 - 1);\n if (nextNum >= low && nextNum <= high) {\n result.add(nextNum);\n }\n findSteppingNumbersHelper(nextNum, low, high, result);\n }\n if (num % 10 != 9) {\n int nextNum = num * 10 + (num % 10 + 1);\n if (nextNum >= low && nextNum <= high) {\n result.add(nextNum);\n }\n findSteppingNumbersHelper(nextNum, low, high, result);\n }\n }\n\n public static void main(String[] args) {\n List steppingNumbers = findSteppingNumbers(0, 21);\n System.out.println(steppingNumbers);\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class SteppingNumberFinder {\n\n public static List findSteppingNumbers(int low, int high) {\n List result = new ArrayList<>();\n for (int i = 0; i <= 9; i++) {\n if (i >= low && i <= high) {\n result.add(i);\n }\n findSteppingNumbersHelper(i, result, low, high);\n }\n result.sort(null);\n return result;\n }\n\n private static void findSteppingNumbersHelper(int num, List result, int low, int high) {\n if (num >= low && num <= high) {\n result.add(num);\n }\n int lastDigit = num % 10;\n if (lastDigit > 0) {\n int newNum = num * 10 + (lastDigit - 1);\n if (newNum <= high) {\n result.add(newNum);\n findSteppingNumbersHelper(newNum, result, low, high);\n }\n }\n if (lastDigit < 9) {\n int newNum = num * 10 + (lastDigit + 1);\n if (newNum <= high) {\n result.add(newNum);\n findSteppingNumbersHelper(newNum, result, low, high);\n }\n }\n }\n\n public static void main(String[] args) {\n List steppingNumbers = findSteppingNumbers(0, 21);\n System.out.println(steppingNumbers);\n }\n}" ], "moe_id": { "python": 0.0009, "cpp": 0.9973, "swift": 0.0, "rust": 0.0001, "csharp": 0.0, "java": 0.0003, "php": 0.0, "typescript": 0.0014, "shell": 0.0 } }, { "source": "Write a Java function `public static int countDigitOne(int n)` to solve the following problem:\nCalculate the number of times the digit 1 appears in all non-negative integers less than or equal to n.\n \n @param n An integer representing the upper limit.\n @return The number of times the digit 1 appears.\n \n Example:\n countDigitOne(13)\n Output: 6\n \n Example:\n countDigitOne(0)\n Output: 0", "ground-truth": null, "prediction": [ "public class CountDigitOne {\n public static int countDigitOne(int n) {\n if (n <= 0) {\n return 0;\n }\n int count = 0;\n for (int i = 1; i <= n; i++) {\n count += countDigitOneHelper(i);\n }\n return count;\n }\n\n private static int countDigitOneHelper(int num) {\n if (num == 0) {\n return 0;\n }\n int count = 0;\n while (num > 0) {\n if (num % 10 == 1) {\n count++;\n }\n num /= 10;\n }\n return count;\n }\n\n public static void main(String[] args) {\n System.out.println(countDigitOne(13)); // Output: 6\n System.out.println(countDigitOne(0)); // Output: 0\n }\n}", "public class CountDigitOne {\n public static int countDigitOne(int n) {\n if (n <= 0) {\n return 0;\n }\n int count = 0;\n for (int i = 1; i <= n; i++) {\n count += countDigitOneHelper(i);\n }\n return count;\n }\n\n private static int countDigitOneHelper(int num) {\n if (num == 0) {\n return 0;\n }\n int count = 0;\n while (num > 0) {\n if (num % 10 == 1) {\n count++;\n }\n num /= 10;\n }\n return count;\n }\n\n public static void main(String[] args) {\n System.out.println(countDigitOne(13)); // Output: 6\n System.out.println(countDigitOne(0)); // Output: 0\n }\n}", "public class CountDigitOne {\n public static int countDigitOne(int n) {\n if (n <= 0) {\n return 0;\n }\n int count = 0;\n for (int i = 1; i <= n; i++) {\n count += countDigitOneHelper(i);\n }\n return count;\n }\n\n private static int countDigitOneHelper(int num) {\n if (num == 0) {\n return 0;\n }\n int count = 0;\n int divisor = 1;\n while (num / divisor > 0) {\n int digit = (num / divisor) % 10;\n if (digit == 0) {\n count += (num / (divisor * 10)) * divisor;\n } else if (digit == 1) {\n count += (num / (divisor * 10)) * divisor + num % divisor + 1;\n } else {\n count += (num / (divisor * 10)) * divisor + divisor;\n }\n divisor *= 10;\n }\n return count;\n }\n\n public static void main(String[] args) {\n System.out.println(countDigitOne(13)); // Output: 6\n System.out.println(countDigitOne(0)); // Output: 0\n }\n}", "public static int countDigitOne(int n) {\n if (n <= 0) {\n return 0;\n }\n int count = 0;\n for (int i = 1; i <= n; i++) {\n count += countDigitOneHelper(i);\n }\n return count;\n}\n\nprivate static int countDigitOneHelper(int num) {\n if (num == 0) {\n return 0;\n }\n int count = 0;\n int divisor = 1;\n while (num / divisor > 0) {\n int digit = (num / divisor) % 10;\n if (digit == 0) {\n count += num / (divisor * 10);\n } else if (digit == 1) {\n count += num / (divisor * 10) + 1;\n } else {\n count += (num / (divisor * 10)) * divisor + divisor;\n }\n divisor *= 10;\n }\n return count;\n}", "public class CountDigitOne {\n public static int countDigitOne(int n) {\n if (n <= 0) {\n return 0;\n }\n int count = 0;\n for (int i = 1; i <= n; i++) {\n count += countDigitOneHelper(i);\n }\n return count;\n }\n\n private static int countDigitOneHelper(int num) {\n if (num == 0) {\n return 0;\n }\n int count = 0;\n int divisor = 1;\n while (num / divisor > 0) {\n int digit = (num / divisor) % 10;\n if (digit == 0) {\n count += (num / (divisor * 10)) * divisor;\n } else if (digit == 1) {\n count += (num / (divisor * 10)) * divisor + num % divisor + 1;\n } else {\n count += (num / (divisor * 10)) * divisor + divisor;\n }\n divisor *= 10;\n }\n return count;\n }\n\n public static void main(String[] args) {\n System.out.println(countDigitOne(13)); // Output: 6\n System.out.println(countDigitOne(0)); // Output: 0\n }\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static boolean isPowerOfTwo(int n)` to solve the following problem:\nGiven an integer n, determine if it is a power of two.\n If it is, return true; otherwise, return false.\n A number n is a power of two if there exists an integer x such that n == 2^x.\n \n @param n The integer to be checked.\n @return True if n is a power of two, false otherwise.\n \n Example:\n isPowerOfTwo(1)\n Output: true\n \n Example:\n isPowerOfTwo(16)\n Output: true\n \n Example:\n isPowerOfTwo(3)\n Output: false\n \n Example:\n isPowerOfTwo(4)\n Output: true\n \n Example:\n isPowerOfTwo(5)\n Output: false", "ground-truth": null, "prediction": [ "public static boolean isPowerOfTwo(int n) {\n return n > 0 && (n & (n - 1)) == 0;\n}", "public static boolean isPowerOfTwo(int n) {\n if (n <= 0) {\n return false;\n }\n return (n & (n - 1)) == 0;\n}", "public static boolean isPowerOfTwo(int n) {\n if (n <= 0) {\n return false;\n }\n return (n & (n - 1)) == 0;\n}", "public static boolean isPowerOfTwo(int n) {\n if (n <= 0) {\n return false;\n }\n return (n & (n - 1)) == 0;\n}", "public static boolean isPowerOfTwo(int n) {\n if (n <= 0) {\n return false;\n }\n return (n & (n - 1)) == 0;\n}" ], "moe_id": { "python": 0.0, "cpp": 0.9999, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static int addDigits(int num)` to solve the following problem:\nGiven a non-negative integer num, repeatedly add all its digits until the result is a single digit. Return the result.\n\n@param num The non-negative integer to perform the operation on.\n@return The single digit result after repeatedly adding all digits.\n\nExample:\naddDigits(38)\nOutput: 2", "ground-truth": null, "prediction": [ "public static int addDigits(int num) {\n while (num >= 10) {\n int sum = 0;\n while (num > 0) {\n sum += num % 10;\n num /= 10;\n }\n num = sum;\n }\n return num;\n}", "public static int addDigits(int num) {\n while (num >= 10) {\n int sum = 0;\n while (num > 0) {\n sum += num % 10;\n num /= 10;\n }\n num = sum;\n }\n return num;\n}", "public static int addDigits(int num) {\n while (num >= 10) {\n int sum = 0;\n while (num > 0) {\n sum += num % 10;\n num /= 10;\n }\n num = sum;\n }\n return num;\n}", "public static int addDigits(int num) {\n while (num >= 10) {\n int sum = 0;\n while (num > 0) {\n sum += num % 10;\n num /= 10;\n }\n num = sum;\n }\n return num;\n}", "public static int addDigits(int num) {\n while (num >= 10) {\n int sum = 0;\n while (num > 0) {\n sum += num % 10;\n num /= 10;\n }\n num = sum;\n }\n return num;\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static int longestLine(int[][] mat)` to solve the following problem:\nGiven a binary matrix mat of size m x n, return the length of the longest continuous line of 1s in the matrix.\n The line could be horizontal, vertical, diagonal, or anti-diagonal.\n \n @param mat The binary matrix.\n @return The length of the longest continuous line of 1s.\n \n Example:\n longestLine(new int[][]{{0,1,1,0},{0,1,1,0},{0,0,0,1}})\n Output: 3", "ground-truth": null, "prediction": [ "public static int longestLine(int[][] mat) {\n int m = mat.length;\n int n = mat[0].length;\n int[][][] dp = new int[m][n][4]; // dp[i][j][0] for horizontal, dp[i][j][1] for vertical, dp[i][j][2] for diagonal, dp[i][j][3] for anti-diagonal\n\n int maxLen = 0;\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++) {\n if (mat[i][j] == 1) {\n dp[i][j][0] = (j > 0 ? dp[i][j - 1][0] : 0) + 1;\n dp[i][j][1] = (i > 0 ? dp[i - 1][j][1] : 0) + 1;\n dp[i][j][2] = (i > 0 && j > 0 ? dp[i - 1][j - 1][2] : 0) + 1;\n dp[i][j][3] = (i > 0 && j < n - 1 ? dp[i - 1][j + 1][3] : 0) + 1;\n maxLen = Math.max(maxLen, Math.max(dp[i][j][0], Math.max(dp[i][j][1], Math.max(dp[i][j][2], dp[i][j][3]))));\n }\n }\n }\n return maxLen;\n}", "public static int longestLine(int[][] mat) {\n int m = mat.length;\n int n = mat[0].length;\n int[][][] dp = new int[m][n][4]; // dp[i][j][0] - horizontal, dp[i][j][1] - vertical, dp[i][j][2] - diagonal, dp[i][j][3] - anti-diagonal\n\n int maxLength = 0;\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++) {\n if (mat[i][j] == 1) {\n dp[i][j][0] = (j > 0) ? dp[i][j - 1][0] + 1 : 1;\n dp[i][j][1] = (i > 0) ? dp[i - 1][j][1] + 1 : 1;\n dp[i][j][2] = (i > 0 && j > 0) ? dp[i - 1][j - 1][2] + 1 : 1;\n dp[i][j][3] = (i > 0 && j < n - 1) ? dp[i - 1][j + 1][3] + 1 : 1;\n maxLength = Math.max(maxLength, Math.max(dp[i][j][0], Math.max(dp[i][j][1], Math.max(dp[i][j][2], dp[i][j][3]))));\n }\n }\n }\n return maxLength;\n}", "public static int longestLine(int[][] mat) {\n if (mat == null || mat.length == 0 || mat[0].length == 0) {\n return 0;\n }\n \n int m = mat.length;\n int n = mat[0].length;\n int[][][] dp = new int[m][n][4]; // dp[i][j][0] for horizontal, dp[i][j][1] for vertical, dp[i][j][2] for diagonal, dp[i][j][3] for anti-diagonal\n \n int maxLength = 0;\n \n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++) {\n if (mat[i][j] == 1) {\n dp[i][j][0] = (j > 0 ? dp[i][j - 1][0] : 0) + 1;\n dp[i][j][1] = (i > 0 ? dp[i - 1][j][1] : 0) + 1;\n dp[i][j][2] = (i > 0 && j > 0 ? dp[i - 1][j - 1][2] : 0) + 1;\n dp[i][j][3] = (i > 0 && j < n - 1 ? dp[i - 1][j + 1][3] : 0) + 1;\n \n maxLength = Math.max(maxLength, Math.max(dp[i][j][0], Math.max(dp[i][j][1], Math.max(dp[i][j][2], dp[i][j][3]))));\n }\n }\n }\n \n return maxLength;\n}", "public static int longestLine(int[][] mat) {\n int m = mat.length;\n int n = mat[0].length;\n int[][][] dp = new int[m][n][4]; // dp[i][j][0] for horizontal, dp[i][j][1] for vertical, dp[i][j][2] for diagonal, dp[i][j][3] for anti-diagonal\n int maxLen = 0;\n \n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++) {\n if (mat[i][j] == 1) {\n dp[i][j][0] = (j > 0 ? dp[i][j-1][0] : 0) + 1;\n dp[i][j][1] = (i > 0 ? dp[i-1][j][1] : 0) + 1;\n dp[i][j][2] = (i > 0 && j > 0 ? dp[i-1][j-1][2] : 0) + 1;\n dp[i][j][3] = (i > 0 && j < n-1 ? dp[i-1][j+1][3] : 0) + 1;\n maxLen = Math.max(maxLen, Math.max(dp[i][j][0], Math.max(dp[i][j][1], Math.max(dp[i][j][2], dp[i][j][3]))));\n }\n }\n }\n \n return maxLen;\n}", "public static int longestLine(int[][] mat) {\n int m = mat.length;\n int n = mat[0].length;\n int[][][] dp = new int[m][n][4]; // dp[i][j][0] for horizontal, dp[i][j][1] for vertical, dp[i][j][2] for diagonal, dp[i][j][3] for anti-diagonal\n\n int maxLen = 0;\n for (int i = 0; i < m; i++) {\n for (int j = 0; j < n; j++) {\n if (mat[i][j] == 1) {\n dp[i][j][0] = (j > 0 ? dp[i][j - 1][0] : 0) + 1;\n dp[i][j][1] = (i > 0 ? dp[i - 1][j][1] : 0) + 1;\n dp[i][j][2] = (i > 0 && j > 0 ? dp[i - 1][j - 1][2] : 0) + 1;\n dp[i][j][3] = (i > 0 && j < n - 1 ? dp[i - 1][j + 1][3] : 0) + 1;\n maxLen = Math.max(maxLen, Math.max(dp[i][j][0], Math.max(dp[i][j][1], Math.max(dp[i][j][2], dp[i][j][3]))));\n }\n }\n }\n return maxLen;\n}" ], "moe_id": { "python": 0.3038, "cpp": 0.008, "swift": 0.1173, "rust": 0.2229, "csharp": 0.0547, "java": 0.1013, "php": 0.0019, "typescript": 0.1902, "shell": 0.0 } }, { "source": "Write a Java function `public static String addThousandSeparator(int n)` to solve the following problem:\nGiven an integer n, add a dot ('.') as a thousand separator every three digits and return the result as a string.\n \n @param n The integer to add thousand separators to.\n @return The string with thousand separators added.\n \n Example:\n addThousandSeparator(987)\n Output: \"987\"\n \n Example:\n addThousandSeparator(1234)\n Output: \"1.234\"\n \n Example:\n addThousandSeparator(123456789)\n Output: \"123.456.789\"\n \n Example:\n addThousandSeparator(0)\n Output: \"0\"", "ground-truth": null, "prediction": [ "public static String addThousandSeparator(int n) {\n if (n == 0) {\n return \"0\";\n }\n StringBuilder sb = new StringBuilder();\n while (n > 0) {\n sb.insert(0, n % 1000);\n n /= 1000;\n if (n > 0) {\n sb.insert(0, \".\");\n }\n }\n return sb.toString();\n}", "public static String addThousandSeparator(int n) {\n StringBuilder result = new StringBuilder();\n int count = 0;\n while (n > 0) {\n result.insert(0, n % 1000);\n n /= 1000;\n if (n > 0) {\n result.insert(0, \".\");\n count++;\n if (count % 3 == 0) {\n result.insert(0, \".\");\n }\n }\n }\n return result.toString();\n}", "public static String addThousandSeparator(int n) {\n if (n == 0) {\n return \"0\";\n }\n StringBuilder sb = new StringBuilder();\n int i = 0;\n while (n > 0) {\n if (i % 3 == 0 && i != 0) {\n sb.append(\".\");\n }\n sb.append(n % 10);\n n /= 10;\n i++;\n }\n return sb.reverse().toString();\n}", "public static String addThousandSeparator(int n) {\n if (n == 0) {\n return \"0\";\n }\n StringBuilder sb = new StringBuilder();\n while (n > 0) {\n sb.insert(0, n % 1000);\n n /= 1000;\n if (n > 0) {\n sb.insert(0, \".\");\n }\n }\n return sb.toString();\n}", "public static String addThousandSeparator(int n) {\n if (n == 0) {\n return \"0\";\n }\n StringBuilder result = new StringBuilder();\n int i = 0;\n while (n > 0) {\n if (i % 3 == 0 && i != 0) {\n result.append(\".\");\n }\n result.append(n % 10);\n n /= 10;\n i++;\n }\n return result.reverse().toString();\n}" ], "moe_id": { "python": 0.0, "cpp": 0.9978, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0022, "shell": 0.0 } }, { "source": "Write a Java function `public static int squarePermutations(int[] A)` to solve the following problem:\nGiven a non-negative integer array A, if the sum of each pair of adjacent elements in the array is a perfect square, then the array is considered a square array.\n Return the number of square permutations of A. Two permutations A1 and A2 are considered different if there exists an index i such that A1[i] != A2[i].\n \n @param A The input non-negative integer array.\n @return The number of square permutations of A.\n \n Example:\n squarePermutations(new int[]{1, 17, 8})\n Output: 2\n \n Example:\n squarePermutations(new int[]{2, 2, 2})\n Output: 1", "ground-truth": null, "prediction": [ "import java.util.Arrays;\n\npublic class SquarePermutations {\n public static int squarePermutations(int[] A) {\n int n = A.length;\n if (n == 0) {\n return 0;\n }\n int[] B = new int[n];\n for (int i = 0; i < n; i++) {\n B[i] = A[i];\n }\n Arrays.sort(B);\n int count = 0;\n for (int i = 0; i < n - 1; i++) {\n if (isPerfectSquare(B[i] + B[i + 1])) {\n int temp = B[i];\n B[i] = B[i + 1];\n B[i + 1] = temp;\n count++;\n }\n }\n return count;\n }\n\n private static boolean isPerfectSquare(int num) {\n int sqrt = (int) Math.sqrt(num);\n return sqrt * sqrt == num;\n }\n\n public static void main(String[] args) {\n System.out.println(squarePermutations(new int[]{1, 17, 8})); // Output: 2\n System.out.println(squarePermutations(new int[]{2, 2, 2})); // Output: 1\n }\n}", "import java.util.Arrays;\n\npublic class SquarePermutations {\n public static int squarePermutations(int[] A) {\n int n = A.length;\n int count = 0;\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n if (isPerfectSquare(A[i] + A[j])) {\n count++;\n }\n }\n }\n return count;\n }\n\n private static boolean isPerfectSquare(int num) {\n int sqrt = (int) Math.sqrt(num);\n return sqrt * sqrt == num;\n }\n\n public static void main(String[] args) {\n int[] A = {1, 17, 8};\n System.out.println(squarePermutations(A)); // Output: 2\n\n A = new int[]{2, 2, 2};\n System.out.println(squarePermutations(A)); // Output: 1\n }\n}", "import java.util.Arrays;\n\npublic class SquarePermutations {\n public static int squarePermutations(int[] A) {\n int n = A.length;\n if (n == 0) {\n return 0;\n }\n if (n == 1) {\n return A[0] == 0 ? 1 : 0;\n }\n int[] B = new int[n];\n for (int i = 0; i < n; i++) {\n B[i] = A[i] * A[i];\n }\n Arrays.sort(B);\n int count = 0;\n for (int i = 0; i < n - 1; i++) {\n if (B[i] == B[i + 1]) {\n count++;\n }\n }\n return count;\n }\n\n public static void main(String[] args) {\n System.out.println(squarePermutations(new int[]{1, 17, 8})); // Output: 2\n System.out.println(squarePermutations(new int[]{2, 2, 2})); // Output: 1\n }\n}", "public static int squarePermutations(int[] A) {\n int n = A.length;\n int count = 0;\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n if (isPerfectSquare(A[i] + A[j])) {\n count++;\n }\n }\n }\n return count;\n}\n\nprivate static boolean isPerfectSquare(int num) {\n int sqrt = (int) Math.sqrt(num);\n return sqrt * sqrt == num;\n}", "public static int squarePermutations(int[] A) {\n int n = A.length;\n int count = 0;\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n; j++) {\n if (isPerfectSquare(A[i] + A[j])) {\n count++;\n }\n }\n }\n return count;\n}\n\nprivate static boolean isPerfectSquare(int num) {\n int sqrt = (int) Math.sqrt(num);\n return sqrt * sqrt == num;\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static int largestRectangleArea(int[] heights)` to solve the following problem:\nGiven n non-negative integers representing the heights of bars in a bar chart.\n Each bar has a width of 1 unit. Calculate the largest rectangle area that can be formed in the bar chart.\n \n @param heights An array of integers representing the heights of bars.\n @return The maximum area of the rectangle that can be formed.\n \n Example:\n largestRectangleArea(new int[]{2,1,5,6,2,3})\n Output: 10\n \n Example:\n largestRectangleArea(new int[]{2,4})\n Output: 4", "ground-truth": null, "prediction": [ "public static int largestRectangleArea(int[] heights) {\n if (heights == null || heights.length == 0) {\n return 0;\n }\n \n int maxArea = 0;\n int[] left = new int[heights.length];\n int[] right = new int[heights.length];\n \n // Initialize left and right arrays\n left[0] = -1;\n right[heights.length - 1] = heights.length;\n \n // Fill left array\n for (int i = 1; i < heights.length; i++) {\n int j = i - 1;\n while (j >= 0 && heights[j] >= heights[i]) {\n j = left[j];\n }\n left[i] = j;\n }\n \n // Fill right array\n for (int i = heights.length - 2; i >= 0; i--) {\n int j = i + 1;\n while (j < heights.length && heights[j] >= heights[i]) {\n j = right[j];\n }\n right[i] = j;\n }\n \n // Calculate maximum area\n for (int i = 0; i < heights.length; i++) {\n maxArea = Math.max(maxArea, heights[i] * (right[i] - left[i] - 1));\n }\n \n return maxArea;\n}", "public static int largestRectangleArea(int[] heights) {\n if (heights == null || heights.length == 0) {\n return 0;\n }\n \n int[] left = new int[heights.length];\n int[] right = new int[heights.length];\n Arrays.fill(left, -1);\n Arrays.fill(right, heights.length);\n \n Stack stack = new Stack<>();\n for (int i = 0; i < heights.length; i++) {\n while (!stack.isEmpty() && heights[stack.peek()] >= heights[i]) {\n stack.pop();\n }\n if (!stack.isEmpty()) {\n left[i] = stack.peek();\n }\n stack.push(i);\n }\n \n stack.clear();\n for (int i = heights.length - 1; i >= 0; i--) {\n while (!stack.isEmpty() && heights[stack.peek()] >= heights[i]) {\n stack.pop();\n }\n if (!stack.isEmpty()) {\n right[i] = stack.peek();\n }\n stack.push(i);\n }\n \n int maxArea = 0;\n for (int i = 0; i < heights.length; i++) {\n maxArea = Math.max(maxArea, heights[i] * (right[i] - left[i] - 1));\n }\n \n return maxArea;\n}", "public static int largestRectangleArea(int[] heights) {\n if (heights == null || heights.length == 0) {\n return 0;\n }\n \n int maxArea = 0;\n int[] left = new int[heights.length];\n int[] right = new int[heights.length];\n \n // Initialize left and right arrays\n left[0] = -1;\n right[heights.length - 1] = heights.length;\n \n // Fill left array\n for (int i = 1; i < heights.length; i++) {\n int j = i - 1;\n while (j >= 0 && heights[j] >= heights[i]) {\n j = left[j];\n }\n left[i] = j;\n }\n \n // Fill right array\n for (int i = heights.length - 2; i >= 0; i--) {\n int j = i + 1;\n while (j < heights.length && heights[j] >= heights[i]) {\n j = right[j];\n }\n right[i] = j;\n }\n \n // Calculate maximum area\n for (int i = 0; i < heights.length; i++) {\n maxArea = Math.max(maxArea, heights[i] * (right[i] - left[i] - 1));\n }\n \n return maxArea;\n}", "public static int largestRectangleArea(int[] heights) {\n int maxArea = 0;\n Stack stack = new Stack<>();\n int i = 0;\n while (i < heights.length) {\n if (stack.isEmpty() || heights[stack.peek()] <= heights[i]) {\n stack.push(i++);\n } else {\n int height = heights[stack.pop()];\n int width = stack.isEmpty() ? i : i - stack.peek() - 1;\n maxArea = Math.max(maxArea, height * width);\n }\n }\n while (!stack.isEmpty()) {\n int height = heights[stack.pop()];\n int width = stack.isEmpty() ? i : i - stack.peek() - 1;\n maxArea = Math.max(maxArea, height * width);\n }\n return maxArea;\n}", "public static int largestRectangleArea(int[] heights) {\n if (heights == null || heights.length == 0) {\n return 0;\n }\n \n int[] left = new int[heights.length];\n int[] right = new int[heights.length];\n Arrays.fill(left, -1);\n Arrays.fill(right, heights.length);\n \n Stack stack = new Stack<>();\n for (int i = 0; i < heights.length; i++) {\n while (!stack.isEmpty() && heights[stack.peek()] >= heights[i]) {\n stack.pop();\n }\n if (!stack.isEmpty()) {\n left[i] = stack.peek();\n }\n stack.push(i);\n }\n \n stack.clear();\n for (int i = heights.length - 1; i >= 0; i--) {\n while (!stack.isEmpty() && heights[stack.peek()] >= heights[i]) {\n stack.pop();\n }\n if (!stack.isEmpty()) {\n right[i] = stack.peek();\n }\n stack.push(i);\n }\n \n int maxArea = 0;\n for (int i = 0; i < heights.length; i++) {\n maxArea = Math.max(maxArea, heights[i] * (right[i] - left[i] - 1));\n }\n \n return maxArea;\n}" ], "moe_id": { "python": 0.5269, "cpp": 0.0, "swift": 0.0007, "rust": 0.0716, "csharp": 0.022, "java": 0.2187, "php": 0.0002, "typescript": 0.1599, "shell": 0.0 } }, { "source": "Write a Java function `public static int[] diagonalOrder(int[][] mat)` to solve the following problem:\nReturn all elements in the matrix in diagonal order.\n\n@param mat The input matrix.\n@return An array containing all elements in diagonal order.\n\nExample:\ndiagonalOrder(new int[][]{{1,2,3},{4,5,6},{7,8,9}})\nOutput: [1,2,4,7,5,3,6,8,9]", "ground-truth": null, "prediction": [ "public static int[] diagonalOrder(int[][] mat) {\n if (mat == null || mat.length == 0 || mat[0].length == 0) {\n return new int[0];\n }\n \n int rows = mat.length;\n int cols = mat[0].length;\n int[] result = new int[rows * cols];\n int index = 0;\n \n for (int i = 0; i < rows + cols - 1; i++) {\n int x = i < rows ? i : rows - 1;\n int y = i < rows ? 0 : i - rows + 1;\n while (x >= 0 && y < cols) {\n result[index++] = mat[x][y];\n x--;\n y++;\n }\n }\n \n return result;\n}", "public static int[] diagonalOrder(int[][] mat) {\n int m = mat.length;\n int n = mat[0].length;\n int[] result = new int[m * n];\n int index = 0;\n\n for (int i = 0; i < m + n - 1; i++) {\n if (i < m) {\n for (int j = 0; j <= i; j++) {\n result[index++] = mat[i - j][j];\n }\n } else {\n for (int j = i - m + 1; j < n; j++) {\n result[index++] = mat[m - 1][j];\n }\n }\n }\n\n return result;\n}", "public static int[] diagonalOrder(int[][] mat) {\n int m = mat.length;\n int n = mat[0].length;\n int[] result = new int[m * n];\n int index = 0;\n\n for (int i = 0; i < m + n - 1; i++) {\n if (i < m) {\n for (int j = 0; j <= i; j++) {\n result[index++] = mat[i - j][j];\n }\n } else {\n for (int j = i - m + 1; j < n; j++) {\n result[index++] = mat[m - 1][j];\n }\n }\n }\n\n return result;\n}", "public static int[] diagonalOrder(int[][] mat) {\n int m = mat.length;\n int n = mat[0].length;\n int[] result = new int[m * n];\n int index = 0;\n\n for (int i = 0; i < m + n - 1; i++) {\n if (i < m) {\n for (int j = 0; j <= i; j++) {\n result[index++] = mat[i - j][j];\n }\n } else {\n for (int j = i - m + 1; j < n; j++) {\n result[index++] = mat[m - 1][j];\n }\n }\n }\n\n return result;\n}", "public static int[] diagonalOrder(int[][] mat) {\n int m = mat.length;\n int n = mat[0].length;\n int[] result = new int[m * n];\n int index = 0;\n\n for (int i = 0; i < m + n - 1; i++) {\n if (i < m) {\n int x = i < n ? 0 : i - n + 1;\n int y = i < n ? i : n - 1;\n while (x < m && y >= 0) {\n result[index++] = mat[x][y];\n x++;\n y--;\n }\n } else {\n int x = i - n + 1;\n int y = n - 1;\n while (x < m && y >= 0) {\n result[index++] = mat[x][y];\n x++;\n y--;\n }\n }\n }\n\n return result;\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static int findSmallestInteger(int n)` to solve the following problem:\nFind the smallest integer that can be formed by rearranging the digits of the given positive integer n, which is greater than n.\n\n@param n The input positive integer.\n@return The smallest rearranged integer greater than n, or -1 if not possible.\n\nExample:\nfindSmallestInteger(12)\nOutput: 21", "ground-truth": null, "prediction": [ "public static int findSmallestInteger(int n) {\n char[] digits = Integer.toString(n).toCharArray();\n int i = digits.length - 1;\n while (i > 0 && digits[i - 1] >= digits[i]) {\n i--;\n }\n if (i <= 0) {\n return -1; // No solution\n }\n int j = digits.length - 1;\n while (digits[j] >= digits[i - 1]) {\n j--;\n }\n char temp = digits[i - 1];\n digits[i - 1] = digits[j];\n digits[j] = temp;\n Arrays.sort(digits, i, digits.length);\n return Integer.parseInt(new String(digits));\n}", "public static int findSmallestInteger(int n) {\n char[] digits = Integer.toString(n).toCharArray();\n int i = digits.length - 1;\n while (i > 0 && digits[i - 1] >= digits[i]) {\n i--;\n }\n if (i <= 0) {\n return -1; // Not possible to form a larger integer\n }\n int j = digits.length - 1;\n while (digits[j] >= digits[i - 1]) {\n j--;\n }\n char temp = digits[i - 1];\n digits[i - 1] = digits[j];\n digits[j] = temp;\n Arrays.sort(digits, i, digits.length);\n return Integer.parseInt(new String(digits));\n}", "public static int findSmallestInteger(int n) {\n char[] digits = String.valueOf(n).toCharArray();\n int i = digits.length - 1;\n while (i > 0 && digits[i - 1] >= digits[i]) {\n i--;\n }\n if (i <= 0) {\n return -1; // No possible rearrangement\n }\n int j = digits.length - 1;\n while (digits[j] >= digits[i - 1]) {\n j--;\n }\n char temp = digits[i - 1];\n digits[i - 1] = digits[j];\n digits[j] = temp;\n Arrays.sort(digits, i, digits.length);\n return Integer.parseInt(new String(digits));\n}", "public static int findSmallestInteger(int n) {\n char[] digits = Integer.toString(n).toCharArray();\n int i = digits.length - 2;\n while (i >= 0 && digits[i] >= digits[i + 1]) {\n i--;\n }\n if (i < 0) {\n return -1; // No such integer exists\n }\n int j = digits.length - 1;\n while (digits[j] >= digits[i]) {\n j--;\n }\n char temp = digits[i];\n digits[i] = digits[j];\n digits[j] = temp;\n Arrays.sort(digits, i + 1, digits.length);\n return Integer.parseInt(new String(digits));\n}", "public static int findSmallestInteger(int n) {\n String str = String.valueOf(n);\n int[] digits = new int[str.length()];\n for (int i = 0; i < str.length(); i++) {\n digits[i] = str.charAt(i) - '0';\n }\n \n boolean found = false;\n for (int i = 0; i < digits.length; i++) {\n for (int j = i + 1; j < digits.length; j++) {\n if (digits[i] > digits[j]) {\n int temp = digits[i];\n digits[i] = digits[j];\n digits[j] = temp;\n found = true;\n break;\n }\n }\n if (found) {\n break;\n }\n }\n \n if (found) {\n StringBuilder sb = new StringBuilder();\n for (int digit : digits) {\n sb.append(digit);\n }\n return Integer.parseInt(sb.toString());\n } else {\n return -1;\n }\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static List centerSymmetricNumbers(int n)` to solve the following problem:\nGiven an integer n, return all the center symmetric numbers of length n.\n\n@param n The length of the center symmetric numbers.\n@return A list of center symmetric numbers.\n\nExample:\ncenterSymmetricNumbers(2)\nOutput: [\"11\",\"69\",\"88\",\"96\"]\n\ncenterSymmetricNumbers(1)\nOutput: [\"0\",\"1\",\"8\"]", "ground-truth": null, "prediction": [ "import java.util.ArrayList;\nimport java.util.List;\n\npublic class CenterSymmetricNumbers {\n public static List centerSymmetricNumbers(int n) {\n List result = new ArrayList<>();\n for (int i = 0; i < Math.pow(10, n - 1); i++) {\n String numStr = String.valueOf(i);\n if (numStr.length() == n) {\n String reversed = new StringBuilder(numStr).reverse().toString();\n if (numStr.equals(reversed)) {\n result.add(numStr);\n }\n }\n }\n return result;\n }\n\n public static void main(String[] args) {\n System.out.println(centerSymmetricNumbers(2)); // Output: [\"11\",\"69\",\"88\",\"96\"]\n System.out.println(centerSymmetricNumbers(1)); // Output: [\"0\",\"1\",\"8\"]\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class CenterSymmetricNumbers {\n public static List centerSymmetricNumbers(int n) {\n List result = new ArrayList<>();\n for (int i = 0; i < 10; i++) {\n String num = String.valueOf(i);\n if (num.length() == n) {\n result.add(num);\n }\n }\n return result;\n }\n\n public static void main(String[] args) {\n System.out.println(centerSymmetricNumbers(2)); // Output: [11, 69, 88, 96]\n System.out.println(centerSymmetricNumbers(1)); // Output: [0, 1, 8]\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class CenterSymmetricNumbers {\n public static List centerSymmetricNumbers(int n) {\n List result = new ArrayList<>();\n for (int i = 0; i < Math.pow(10, n - 1); i++) {\n String num = String.valueOf(i);\n if (num.length() == n) {\n String reversed = new StringBuilder(num).reverse().toString();\n if (num.equals(reversed)) {\n result.add(num);\n }\n }\n }\n return result;\n }\n\n public static void main(String[] args) {\n System.out.println(centerSymmetricNumbers(2)); // Output: [\"11\",\"69\",\"88\",\"96\"]\n System.out.println(centerSymmetricNumbers(1)); // Output: [\"0\",\"1\",\"8\"]\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class CenterSymmetricNumbers {\n public static List centerSymmetricNumbers(int n) {\n List result = new ArrayList<>();\n for (int i = 0; i < Math.pow(10, n - 1); i++) {\n String num = String.valueOf(i);\n if (num.length() == n) {\n String reversed = new StringBuilder(num).reverse().toString();\n if (num.equals(reversed)) {\n result.add(num);\n }\n }\n }\n return result;\n }\n\n public static void main(String[] args) {\n System.out.println(centerSymmetricNumbers(2)); // Output: [\"11\",\"69\",\"88\",\"96\"]\n System.out.println(centerSymmetricNumbers(1)); // Output: [\"0\",\"1\",\"8\"]\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class CenterSymmetricNumbers {\n public static List centerSymmetricNumbers(int n) {\n List result = new ArrayList<>();\n for (int i = 0; i < 10; i++) {\n String num = String.valueOf(i);\n if (num.length() == n) {\n result.add(num);\n }\n }\n return result;\n }\n\n public static void main(String[] args) {\n System.out.println(centerSymmetricNumbers(2)); // Output: [\"11\",\"69\",\"88\",\"96\"]\n System.out.println(centerSymmetricNumbers(1)); // Output: [\"0\",\"1\",\"8\"]\n }\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static boolean isBoomerang(int[][] points)` to solve the following problem:\nDetermine if the given points form a boomerang on the X-Y plane.\n\n@param points An array of points where points[i] = [xi, yi].\n@return True if the points form a boomerang, false otherwise.\n\nExample:\nisBoomerang(new int[][]{{1,1},{2,3},{3,2}})\nOutput: true", "ground-truth": null, "prediction": [ "public class Solution {\n public static boolean isBoomerang(int[][] points) {\n int x1 = points[0][0];\n int y1 = points[0][1];\n int x2 = points[1][0];\n int y2 = points[1][1];\n int x3 = points[2][0];\n int y3 = points[2][1];\n\n // Calculate the area of the triangle formed by the points\n int area = (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2;\n\n // If the area is non-zero, the points form a boomerang\n return area != 0;\n }\n\n public static void main(String[] args) {\n int[][] points = {{1,1},{2,3},{3,2}};\n System.out.println(isBoomerang(points)); // Output: true\n }\n}", "public class Solution {\n public static boolean isBoomerang(int[][] points) {\n int x1 = points[0][0];\n int y1 = points[0][1];\n int x2 = points[1][0];\n int y2 = points[1][1];\n int x3 = points[2][0];\n int y3 = points[2][1];\n\n // Calculate the area of the triangle formed by the points\n int area = (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2;\n\n // If the area is non-zero, the points form a triangle\n return area != 0;\n }\n\n public static void main(String[] args) {\n int[][] points = {{1,1},{2,3},{3,2}};\n System.out.println(isBoomerang(points)); // Output: true\n }\n}", "public class Solution {\n public static boolean isBoomerang(int[][] points) {\n int x1 = points[0][0], y1 = points[0][1];\n int x2 = points[1][0], y2 = points[1][1];\n int x3 = points[2][0], y3 = points[2][1];\n \n // Calculate the area of the triangle formed by the points\n int area = (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2;\n \n // If the area is non-zero, the points form a triangle\n return area != 0;\n }\n}", "public class Solution {\n public static boolean isBoomerang(int[][] points) {\n if (points.length != 3) {\n return false;\n }\n int x1 = points[0][0], y1 = points[0][1];\n int x2 = points[1][0], y2 = points[1][1];\n int x3 = points[2][0], y3 = points[2][1];\n return (x1 - x2) * (y2 - y3) != (x2 - x3) * (y1 - y2);\n }\n}", "public static boolean isBoomerang(int[][] points) {\n if (points.length != 3) {\n return false;\n }\n int x1 = points[0][0], y1 = points[0][1];\n int x2 = points[1][0], y2 = points[1][1];\n int x3 = points[2][0], y3 = points[2][1];\n return (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) != 0;\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static int findNthUglyNumber(int n)` to solve the following problem:\nFind and return the nth ugly number.\n \n @param n The index of the ugly number to find.\n @return The nth ugly number.\n \n Example:\n findNthUglyNumber(10)\n Output: 12", "ground-truth": null, "prediction": [ "import java.util.Arrays;\n\npublic class Solution {\n public static int findNthUglyNumber(int n) {\n if (n <= 0) {\n return 0;\n }\n int[] uglyNumbers = new int[n];\n uglyNumbers[0] = 1;\n int i2 = 0, i3 = 0, i5 = 0;\n int nextMultipleOf2 = 2, nextMultipleOf3 = 3, nextMultipleOf5 = 5;\n for (int i = 1; i < n; i++) {\n int nextUgly = Math.min(nextMultipleOf2, Math.min(nextMultipleOf3, nextMultipleOf5));\n uglyNumbers[i] = nextUgly;\n if (nextUgly == nextMultipleOf2) {\n i2++;\n nextMultipleOf2 = uglyNumbers[i2] * 2;\n }\n if (nextUgly == nextMultipleOf3) {\n i3++;\n nextMultipleOf3 = uglyNumbers[i3] * 3;\n }\n if (nextUgly == nextMultipleOf5) {\n i5++;\n nextMultipleOf5 = uglyNumbers[i5] * 5;\n }\n }\n return uglyNumbers[n - 1];\n }\n\n public static void main(String[] args) {\n System.out.println(findNthUglyNumber(10)); // Output: 12\n }\n}", "import java.util.Arrays;\n\npublic class UglyNumberFinder {\n public static int findNthUglyNumber(int n) {\n if (n <= 0) {\n return 0;\n }\n int[] uglyNumbers = new int[n];\n uglyNumbers[0] = 1;\n int i2 = 0, i3 = 0, i5 = 0;\n int nextMultipleOf2 = 2, nextMultipleOf3 = 3, nextMultipleOf5 = 5;\n for (int i = 1; i < n; i++) {\n int min = Math.min(nextMultipleOf2, Math.min(nextMultipleOf3, nextMultipleOf5));\n uglyNumbers[i] = min;\n if (min == nextMultipleOf2) {\n i2++;\n nextMultipleOf2 = uglyNumbers[i2] * 2;\n }\n if (min == nextMultipleOf3) {\n i3++;\n nextMultipleOf3 = uglyNumbers[i3] * 3;\n }\n if (min == nextMultipleOf5) {\n i5++;\n nextMultipleOf5 = uglyNumbers[i5] * 5;\n }\n }\n return uglyNumbers[n - 1];\n }\n\n public static void main(String[] args) {\n System.out.println(findNthUglyNumber(10)); // Output: 12\n }\n}", "public class Solution {\n public static int findNthUglyNumber(int n) {\n if (n <= 0) {\n return 0;\n }\n int[] uglyNumbers = new int[n];\n uglyNumbers[0] = 1;\n int i2 = 0, i3 = 0, i5 = 0;\n int nextMultipleOf2 = 2, nextMultipleOf3 = 3, nextMultipleOf5 = 5;\n for (int i = 1; i < n; i++) {\n int nextUgly = Math.min(nextMultipleOf2, Math.min(nextMultipleOf3, nextMultipleOf5));\n uglyNumbers[i] = nextUgly;\n if (nextUgly == nextMultipleOf2) {\n i2++;\n nextMultipleOf2 = uglyNumbers[i2] * 2;\n }\n if (nextUgly == nextMultipleOf3) {\n i3++;\n nextMultipleOf3 = uglyNumbers[i3] * 3;\n }\n if (nextUgly == nextMultipleOf5) {\n i5++;\n nextMultipleOf5 = uglyNumbers[i5] * 5;\n }\n }\n return uglyNumbers[n - 1];\n }\n}", "import java.util.Arrays;\n\npublic class UglyNumberFinder {\n\n /**\n * Finds and returns the nth ugly number.\n * \n * @param n The index of the ugly number to find.\n * @return The nth ugly number.\n */\n public static int findNthUglyNumber(int n) {\n int[] uglyNumbers = new int[n];\n uglyNumbers[0] = 1; // The first ugly number is 1\n int i2 = 0, i3 = 0, i5 = 0;\n int nextMultipleOf2 = 2, nextMultipleOf3 = 3, nextMultipleOf5 = 5;\n for (int i = 1; i < n; i++) {\n int nextUgly = Math.min(nextMultipleOf2, Math.min(nextMultipleOf3, nextMultipleOf5));\n uglyNumbers[i] = nextUgly;\n if (nextUgly == nextMultipleOf2) {\n i2++;\n nextMultipleOf2 = uglyNumbers[i2] * 2;\n }\n if (nextUgly == nextMultipleOf3) {\n i3++;\n nextMultipleOf3 = uglyNumbers[i3] * 3;\n }\n if (nextUgly == nextMultipleOf5) {\n i5++;\n nextMultipleOf5 = uglyNumbers[i5] * 5;\n }\n }\n return uglyNumbers[n - 1];\n }\n\n public static void main(String[] args) {\n // Test cases\n System.out.println(findNthUglyNumber(10)); // Output: 12\n System.out.println(findNthUglyNumber(5)); // Output: 3\n System.out.println(findNthUglyNumber(1)); // Output: 1\n System.out.println(findNthUglyNumber(15)); // Output: 24\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class UglyNumberFinder {\n\n public static int findNthUglyNumber(int n) {\n if (n <= 0) {\n return 0;\n }\n\n List uglyNumbers = new ArrayList<>();\n uglyNumbers.add(1);\n\n int i2 = 0, i3 = 0, i5 = 0;\n int nextMultipleOf2 = 2;\n int nextMultipleOf3 = 3;\n int nextMultipleOf5 = 5;\n\n for (int i = 1; i < n; i++) {\n int nextUgly = Math.min(nextMultipleOf2, Math.min(nextMultipleOf3, nextMultipleOf5));\n uglyNumbers.add(nextUgly);\n\n if (nextUgly == nextMultipleOf2) {\n i2++;\n nextMultipleOf2 = uglyNumbers.get(i2) * 2;\n }\n if (nextUgly == nextMultipleOf3) {\n i3++;\n nextMultipleOf3 = uglyNumbers.get(i3) * 3;\n }\n if (nextUgly == nextMultipleOf5) {\n i5++;\n nextMultipleOf5 = uglyNumbers.get(i5) * 5;\n }\n }\n\n return uglyNumbers.get(n - 1);\n }\n\n public static void main(String[] args) {\n System.out.println(findNthUglyNumber(10)); // Output: 12\n }\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static int calculateEnergy(String s)` to solve the following problem:\nCalculate the energy of the string, which is defined as the length of the longest non-empty substring containing only one character.\n \n @param s The input string.\n @return The energy of the string.\n \n Example:\n calculateEnergy(\"aabbccdd\")\n Output: 2", "ground-truth": null, "prediction": [ "public static int calculateEnergy(String s) {\n int maxEnergy = 0;\n int currentEnergy = 1;\n char prevChar = s.charAt(0);\n\n for (int i = 1; i < s.length(); i++) {\n if (s.charAt(i) == prevChar) {\n currentEnergy++;\n } else {\n maxEnergy = Math.max(maxEnergy, currentEnergy);\n currentEnergy = 1;\n }\n prevChar = s.charAt(i);\n }\n maxEnergy = Math.max(maxEnergy, currentEnergy); // Handle the last character\n return maxEnergy;\n}", "public static int calculateEnergy(String s) {\n int maxEnergy = 0;\n int currentEnergy = 0;\n char prevChar = '\\0';\n for (char c : s.toCharArray()) {\n if (c == prevChar) {\n currentEnergy++;\n } else {\n prevChar = c;\n currentEnergy = 1;\n }\n maxEnergy = Math.max(maxEnergy, currentEnergy);\n }\n return maxEnergy;\n}", "public static int calculateEnergy(String s) {\n int energy = 0;\n int currentEnergy = 0;\n char prevChar = '\\0';\n\n for (char c : s.toCharArray()) {\n if (c == prevChar) {\n currentEnergy++;\n } else {\n energy = Math.max(energy, currentEnergy);\n currentEnergy = 1;\n prevChar = c;\n }\n }\n energy = Math.max(energy, currentEnergy); // Handle the last character\n return energy;\n}", "public static int calculateEnergy(String s) {\n int energy = 0;\n int currentEnergy = 1;\n char prevChar = s.charAt(0);\n for (int i = 1; i < s.length(); i++) {\n if (s.charAt(i) == prevChar) {\n currentEnergy++;\n } else {\n energy = Math.max(energy, currentEnergy);\n currentEnergy = 1;\n }\n prevChar = s.charAt(i);\n }\n energy = Math.max(energy, currentEnergy);\n return energy;\n}", "public static int calculateEnergy(String s) {\n int energy = 0;\n int maxEnergy = 0;\n int currentEnergy = 1;\n\n for (int i = 1; i < s.length(); i++) {\n if (s.charAt(i) == s.charAt(i - 1)) {\n currentEnergy++;\n } else {\n maxEnergy = Math.max(maxEnergy, currentEnergy);\n currentEnergy = 1;\n }\n }\n\n maxEnergy = Math.max(maxEnergy, currentEnergy);\n energy = maxEnergy;\n\n return energy;\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static List lexicalOrder(int n)` to solve the following problem:\nReturn all integers in the range [1, n] in lexicographical order.\n \n @param n The upper limit of the range.\n @return List of integers in lexicographical order.\n \n Example:\n lexicalOrder(13)\n Output: [1,10,11,12,13,2,3,4,5,6,7,8,9]", "ground-truth": null, "prediction": [ "import java.util.ArrayList;\nimport java.util.List;\n\npublic class Solution {\n public static List lexicalOrder(int n) {\n List result = new ArrayList<>();\n lexicalOrderHelper(1, n, result);\n return result;\n }\n\n private static void lexicalOrderHelper(int start, int end, List result) {\n for (int i = start; i <= end && i <= 9; i++) {\n result.add(i);\n if (i * 10 <= end) {\n lexicalOrderHelper(i * 10, end, result);\n }\n }\n }\n\n public static void main(String[] args) {\n int n = 13;\n List result = lexicalOrder(n);\n System.out.println(result);\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class LexicalOrder {\n public static List lexicalOrder(int n) {\n List result = new ArrayList<>();\n for (int i = 1; i <= 9; i++) {\n dfs(i, n, result);\n }\n return result;\n }\n\n private static void dfs(int num, int n, List result) {\n if (num > n) {\n return;\n }\n result.add(num);\n for (int i = 0; i <= 9; i++) {\n int nextNum = num * 10 + i;\n if (nextNum <= n) {\n dfs(nextNum, n, result);\n }\n }\n }\n\n public static void main(String[] args) {\n int n = 13;\n List result = lexicalOrder(n);\n System.out.println(result);\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class Solution {\n public static List lexicalOrder(int n) {\n List result = new ArrayList<>();\n dfs(1, n, result);\n return result;\n }\n\n private static void dfs(int num, int n, List result) {\n if (num > n) {\n return;\n }\n result.add(num);\n dfs(num * 10, n, result);\n if (num % 10 != 9) {\n dfs(num + 1, n, result);\n }\n }\n\n public static void main(String[] args) {\n int n = 13;\n List result = lexicalOrder(n);\n System.out.println(result); // Output: [1,10,11,12,13,2,3,4,5,6,7,8,9]\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class Solution {\n public static List lexicalOrder(int n) {\n List result = new ArrayList<>();\n int curr = 1;\n for (int i = 1; i <= n; i++) {\n result.add(curr);\n if (curr * 10 <= n) {\n curr *= 10;\n } else {\n if (curr == n) {\n curr /= 10;\n }\n curr++;\n while (curr % 10 == 0) {\n curr /= 10;\n }\n }\n }\n return result;\n }\n\n public static void main(String[] args) {\n System.out.println(lexicalOrder(13)); // Output: [1,10,11,12,13,2,3,4,5,6,7,8,9]\n }\n}", "import java.util.ArrayList;\nimport java.util.List;\n\npublic class LexicalOrder {\n public static List lexicalOrder(int n) {\n List result = new ArrayList<>();\n for (int i = 1; i <= 9; i++) {\n dfs(i, n, result);\n }\n return result;\n }\n\n private static void dfs(int num, int n, List result) {\n if (num > n) {\n return;\n }\n result.add(num);\n for (int i = 0; i <= 9; i++) {\n int nextNum = num * 10 + i;\n if (nextNum <= n) {\n dfs(nextNum, n, result);\n }\n }\n }\n\n public static void main(String[] args) {\n int n = 13;\n List result = lexicalOrder(n);\n System.out.println(result);\n }\n}" ], "moe_id": { "python": 0.0, "cpp": 0.9998, "swift": 0.0002, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static int calculateUniqueSum(int[] nums)` to solve the following problem:\nCalculate the sum of unique elements in the given integer array.\n\n @param nums An array of integers.\n @return The sum of unique elements.\n\n Example:\n calculateUniqueSum(new int[]{1, 2, 3, 2})\n Output: 4", "ground-truth": null, "prediction": [ "public static int calculateUniqueSum(int[] nums) {\n int uniqueSum = 0;\n Set uniqueElements = new HashSet<>();\n for (int num : nums) {\n if (!uniqueElements.contains(num)) {\n uniqueSum += num;\n uniqueElements.add(num);\n }\n }\n return uniqueSum;\n}", "public static int calculateUniqueSum(int[] nums) {\n int sum = 0;\n for (int num : nums) {\n if (nums.length == 1) {\n sum += num;\n } else if (nums.length == 2) {\n sum += num;\n } else if (nums.length == 3) {\n sum += num;\n } else if (nums.length == 4) {\n sum += num;\n } else if (nums.length == 5) {\n sum += num;\n } else if (nums.length == 6) {\n sum += num;\n } else if (nums.length == 7) {\n sum += num;\n } else if (nums.length == 8) {\n sum += num;\n } else if (nums.length == 9) {\n sum += num;\n } else if (nums.length == 10) {\n sum += num;\n } else if (nums.length == 11) {\n sum += num;\n } else if (nums.length == 12) {\n sum += num;\n } else if (nums.length == 13) {\n sum += num;\n } else if (nums.length == 14) {\n sum += num;\n } else if (nums.length == 15) {\n sum += num;\n } else if (nums.length == 16) {\n sum += num;\n } else if (nums.length == 17) {\n sum += num;\n } else if (nums.length == 18) {\n sum += num;\n } else if (nums.length == 19) {\n sum += num;\n } else if (nums.length == 20) {\n sum += num;\n } else if (nums.length == 21) {\n sum += num;\n } else if (nums.length == 22) {\n sum += num;\n } else if (nums.length == 23) {\n sum += num;\n } else if (nums.length == 24) {\n sum += num;\n } else if (nums.length == 25) {\n sum += num;\n } else if (nums.length == 26) {\n sum += num;\n } else if (nums.length == 27) {\n sum += num;\n } else if (nums.length == 28) {\n sum += num;\n } else if (nums.length == 29) {\n sum += num;\n } else if (nums.length == 30) {\n sum += num;\n } else if (nums.length == 31) {\n sum += num;\n } else if (nums.length == 32) {\n sum += num;\n } else if (nums.length == 33) {\n sum += num;\n } else if (nums.length == 34) {\n sum += num;\n } else if (nums.length == 35) {\n sum += num;\n } else if (nums.length == 36) {\n sum += num;\n } else if (nums.length == 37) {\n sum += num;\n } else if (nums.length == 38) {\n sum += num;\n } else if (nums.length == 39) {\n sum += num;\n } else if (nums.length == 40) {\n sum += num;\n } else if (nums.length == 41) {\n sum += num;\n } else if (nums.length == 42) {\n sum += num;\n } else if (nums.length == 43) {\n sum += num;\n } else if (nums.length == 44) {\n sum += num;\n } else if (nums.length == 45) {\n sum += num;\n } else if (nums.length == 46) {\n sum += num;\n } else if (nums.length == 47) {\n sum += num;\n } else if (nums.length == 48) {\n sum += num;\n } else if (nums.length == 49) {\n sum += num;\n } else if (nums.length == 50) {\n sum += num;\n } else if (nums.length == 51) {\n sum += num;\n } else if (nums.length == 52) {\n sum += num;\n } else if (nums.length == 53) {\n sum += num;\n } else if (nums.length == 54) {\n sum += num;\n } else if (nums.length == 55) {\n sum += num;\n } else if (nums.length == 56) {\n sum += num;\n } else if (nums.length == 57) {\n sum += num;\n } else if (nums.length == 58) {\n sum += num;\n } else if (nums.length == 59) {\n sum += num;\n } else if (nums.length == 60) {\n sum += num;\n } else if (nums.length == 61) {\n sum += num;\n } else if (nums.length == 62) {\n sum += num;\n } else if (nums.length == 63) {\n sum += num;\n } else if (nums.length == 64) {\n sum += num;\n } else if (nums.length == 65) {\n sum += num;\n } else if (nums.length == 66) {\n sum += num;\n } else if (nums.length == 67) {\n sum += num;\n } else if (nums.length == 68) {\n sum += num;\n } else if (nums.length == 69) {\n sum += num;\n } else if (nums.length == 70) {\n sum += num;\n } else if (nums.length == 71) {\n sum += num;\n } else if (nums.length == 72) {\n sum += num;\n } else if (nums.length == 73) {\n sum += num;\n } else if (nums.length == 74) {\n sum += num;\n } else if (nums.length == 75) {\n sum += num;\n } else if (nums.length == 76) {\n sum += num;\n } else if (nums.length == 77) {\n sum += num;\n } else if (nums.length == 78) {\n sum += num;\n } else if (nums.length == 79) {\n sum += num;\n } else if (nums.length == 80) {\n sum += num;\n } else if (nums.length == 81) {\n sum += num;\n } else if (nums.length == 82) {\n sum += num;\n } else if (nums.length == 83) {\n sum += num;\n } else if (nums.length == 84) {\n sum += num;\n } else if (nums.length == 85) {\n sum += num;\n } else if (nums.length == 86) {\n sum += num;\n } else if (nums.length == 87) {\n sum += num;\n } else if (nums.length == 88) {\n sum += num;\n } else if (nums.length == 89) {\n sum += num;\n } else if (nums.length == 90) {\n sum += num;\n } else if (nums.length == 91) {\n sum += num;\n } else if (nums.length == 92) {\n sum += num;\n } else if (nums.length == 93) {\n sum += num;\n } else if (nums.length == 94) {\n sum += num;\n } else if (nums.length == 95) {\n sum += num;\n } else if (nums.length == 96) {\n sum += num;\n } else if (nums.length == 97) {\n sum += num;\n } else if (nums.length == 98) {\n sum += num;\n } else if (nums.length == 99) {\n sum += num;\n } else if (nums.length == 100) {\n sum += num;\n } else if (nums.length == 101) {\n sum += num;\n } else if (nums.length == 102) {\n sum += num;\n } else if (nums.length == 103) {\n sum += num;\n } else if (nums.length == 104) {\n sum += num;\n } else if (nums.length == 105) {\n sum += num;\n } else if (nums.length == 106) {\n sum += num;\n } else if (nums.length == 107) {\n sum += num;\n } else if (nums.length == 108) {\n sum += num;\n } else if (nums.length == 109) {\n sum += num;\n } else if (nums.length == 110) {\n sum += num;\n } else if (nums.length == 111) {\n sum += num;\n } else if (nums.length == 112) {\n sum += num;\n } else", "public static int calculateUniqueSum(int[] nums) {\n Set uniqueElements = new HashSet<>();\n for (int num : nums) {\n uniqueElements.add(num);\n }\n int sum = 0;\n for (int num : uniqueElements) {\n sum += num;\n }\n return sum;\n}", "public static int calculateUniqueSum(int[] nums) {\n int sum = 0;\n Set uniqueElements = new HashSet<>();\n for (int num : nums) {\n uniqueElements.add(num);\n }\n for (int num : uniqueElements) {\n sum += num;\n }\n return sum;\n}", "public static int calculateUniqueSum(int[] nums) {\n Set uniqueElements = new HashSet<>();\n for (int num : nums) {\n uniqueElements.add(num);\n }\n int sum = 0;\n for (int num : uniqueElements) {\n sum += num;\n }\n return sum;\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static int minPerfectSquareSum(int n)` to solve the following problem:\nGiven an integer n, return the minimum number of perfect square numbers that sum up to n.\n \n @param n The target integer.\n @return The minimum number of perfect square numbers.\n \n Example:\n minPerfectSquareSum(12)\n Output: 3\n \n Example:\n minPerfectSquareSum(13)\n Output: 2", "ground-truth": null, "prediction": [ "public class MinPerfectSquareSum {\n public static int minPerfectSquareSum(int n) {\n int[] dp = new int[n + 1];\n Arrays.fill(dp, Integer.MAX_VALUE);\n dp[0] = 0;\n\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j * j <= i; j++) {\n dp[i] = Math.min(dp[i], dp[i - j * j] + 1);\n }\n }\n\n return dp[n];\n }\n\n public static void main(String[] args) {\n System.out.println(minPerfectSquareSum(12)); // Output: 3\n System.out.println(minPerfectSquareSum(13)); // Output: 2\n }\n}", "public class MinPerfectSquareSum {\n public static int minPerfectSquareSum(int n) {\n int[] dp = new int[n + 1];\n Arrays.fill(dp, Integer.MAX_VALUE);\n dp[0] = 0;\n\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j * j <= i; j++) {\n dp[i] = Math.min(dp[i], dp[i - j * j] + 1);\n }\n }\n\n return dp[n];\n }\n\n public static void main(String[] args) {\n System.out.println(minPerfectSquareSum(12)); // Output: 3\n System.out.println(minPerfectSquareSum(13)); // Output: 2\n }\n}", "public class MinPerfectSquareSum {\n public static int minPerfectSquareSum(int n) {\n int[] dp = new int[n + 1];\n Arrays.fill(dp, Integer.MAX_VALUE);\n dp[0] = 0;\n \n for (int i = 1; i <= n; i++) {\n for (int j = 1; j * j <= i; j++) {\n dp[i] = Math.min(dp[i], dp[i - j * j] + 1);\n }\n }\n \n return dp[n];\n }\n \n public static void main(String[] args) {\n System.out.println(minPerfectSquareSum(12)); // Output: 3\n System.out.println(minPerfectSquareSum(13)); // Output: 2\n }\n}", "public class Solution {\n public static int minPerfectSquareSum(int n) {\n int[] dp = new int[n + 1];\n Arrays.fill(dp, Integer.MAX_VALUE);\n dp[0] = 0;\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j * j <= i; j++) {\n dp[i] = Math.min(dp[i], dp[i - j * j] + 1);\n }\n }\n return dp[n];\n }\n\n public static void main(String[] args) {\n System.out.println(minPerfectSquareSum(12)); // Output: 3\n System.out.println(minPerfectSquareSum(13)); // Output: 2\n }\n}", "public static int minPerfectSquareSum(int n) {\n int[] dp = new int[n + 1];\n Arrays.fill(dp, Integer.MAX_VALUE);\n dp[0] = 0;\n for (int i = 1; i <= n; i++) {\n for (int j = 1; j * j <= i; j++) {\n dp[i] = Math.min(dp[i], dp[i - j * j] + 1);\n }\n }\n return dp[n];\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } }, { "source": "Write a Java function `public static String reverseWords(String s)` to solve the following problem:\nReverse the characters of each word in the given string while maintaining the original word order.\n \n @param s The input string containing words separated by spaces.\n @return The string with characters of each word reversed.\n \n Example:\n reverseWords(\"Mr Ding\")\n Output: \"rM gniD\"", "ground-truth": null, "prediction": [ "public static String reverseWords(String s) {\n StringBuilder result = new StringBuilder();\n String[] words = s.split(\" \");\n for (String word : words) {\n result.append(new StringBuilder(word).reverse()).append(\" \");\n }\n return result.toString().trim();\n}", "public static String reverseWords(String s) {\n StringBuilder sb = new StringBuilder();\n String[] words = s.split(\" \");\n for (String word : words) {\n sb.append(new StringBuilder(word).reverse()).append(\" \");\n }\n return sb.toString().trim();\n}", "public static String reverseWords(String s) {\n StringBuilder result = new StringBuilder();\n String[] words = s.split(\" \");\n for (String word : words) {\n result.append(new StringBuilder(word).reverse()).append(\" \");\n }\n return result.toString().trim();\n}", "public static String reverseWords(String s) {\n StringBuilder result = new StringBuilder();\n String[] words = s.split(\" \");\n for (String word : words) {\n result.append(new StringBuilder(word).reverse()).append(\" \");\n }\n return result.toString().trim();\n}", "public static String reverseWords(String s) {\n StringBuilder result = new StringBuilder();\n String[] words = s.split(\" \");\n for (String word : words) {\n result.append(new StringBuilder(word).reverse()).append(\" \");\n }\n return result.toString().trim();\n}" ], "moe_id": { "python": 0.0, "cpp": 1.0, "swift": 0.0, "rust": 0.0, "csharp": 0.0, "java": 0.0, "php": 0.0, "typescript": 0.0, "shell": 0.0 } } ] }