{"dataset": "mbjp", "name": "MBJP", "kind": "human-rated", "samples": [{"task_id": "MBJP/1", "source": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport java.math.*;\n\nclass MinCost {\n    /**\n     * * Write a function to find the minimum cost path to reach (m, n) from (0, 0) for the given cost matrix cost[][] and a position (m, n) in cost[][].\n     *\n     * > minCost([[1, 2, 3], [4, 8, 2], [1, 5, 3]], 2, 2)\n     * 8\n     * > minCost([[2, 3, 4], [5, 9, 3], [2, 6, 4]], 2, 2)\n     * 12\n     * > minCost([[3, 4, 5], [6, 10, 4], [3, 7, 5]], 2, 2)\n     * 16\n     */\n    public static int minCost(List<List<Integer>> cost, int m, int n) {\n        // Initialize a 2D array of size (m+1) x (n+1) filled with zeros\n        int[][] d = new int[m + 1][n + 1];\n        // Loop over rows from 0 to m\n        for (int i = 0; i <= m; i++) {\n            // Loop over columns from 0 to n\n            for (int j = 0; j <= n; j++) {\n                // Assigning i1 to current row index, j1 to current column index\n                int i1 = i;\n                int j1 = j;\n                // Variables to store costs from neighboring cells\n                int min1 = Integer.MAX_VALUE;\n                int min2 = Integer.MAX_VALUE;\n                int min3 = Integer.MAX_VALUE;\n                // Check if current cell is at (0,0)\n                if (i1 == 0 && j1 == 0) {\n                    // Base case: cost at starting point\n                    d[i1][j1] = cost.get(i1).get(j1);\n                } else {\n                    // If above row exists, get cost from the cell above\n                    if (i1 - 1 >= 0) {\n                        min1 = d[i1 - 1][j1] + cost.get(i1).get(j1);\n                    }\n                    // If left column exists, get cost from the cell to the left\n                    if (j1 - 1 >= 0) {\n                        min2 = d[i1][j1 - 1] + cost.get(i1).get(j1);\n                    }\n                    // If diagonal cell exists, get cost from diagonal\n                    if (i1 - 1 >= 0 && j1 - 1 >= 0) {\n                        min3 = d[i1 - 1][j1 - 1] + cost.get(i1).get(j1);\n                    }\n                    // Assign the minimum of the three possible costs\n                    int[] temp = {min1, min2, min3};\n                    Arrays.sort(temp);\n                    d[i1][j1] = temp[0];\n                }\n            }\n        }\n        // Return the cost to reach cell (m, n)\n        return d[m][n];\n    }\n}", "human_rating": 3.0, "metadata": {}}, {"task_id": "MBJP/10", "source": "import java.util.*;\n\nclass SmallNnum {\n    /**\n     * * Write a function to get the n smallest items from a dataset.\n     *\n     * > smallNnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100], 2)\n     * [10, 20]\n     * > smallNnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100], 5)\n     * [10, 20, 20, 40, 50]\n     * > smallNnum([10, 20, 50, 70, 90, 20, 50, 40, 60, 80, 100], 3)\n     * [10, 20, 20]\n     */\n    public static List<Integer> smallNnum(List<Integer> list1, int n) {\n        List<Integer> result = new ArrayList<>();\n        PriorityQueue<Integer> minHeap = new PriorityQueue<>(list1);\n        for (int i = 0; i < n; i++) {\n            if (!minHeap.isEmpty()) {\n                result.add(minHeap.poll());\n            }\n        }\n        return result;\n    }\n}", "human_rating": 4.5, "metadata": {}}, {"task_id": "MBJP/11", "source": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport java.math.*;\n\nclass RemoveOcc {\n    /**\n     * * Write a Java function to remove first and last occurrence of a given character from the string.\n     *\n     * > removeOcc(\"hello\", \"l\")\n     * \"heo\"\n     * > removeOcc(\"abcda\", \"a\")\n     * \"bcd\"\n     * > removeOcc(\"PHP\", \"P\")\n     * \"H\"\n     */\n    public static String removeOcc(String s, String ch) {\n        if (s == null || ch == null || ch.length() != 1 || s.isEmpty()) {\n            return s;\n        }\n        char target = ch.charAt(0);\n        int firstIndex = s.indexOf(target);\n        int lastIndex = s.lastIndexOf(target);\n        if (firstIndex == -1 || firstIndex == lastIndex) {\n            // character not found or occurs only once, no removal needed\n            return s;\n        }\n        StringBuilder result = new StringBuilder();\n        for (int i = 0; i < s.length(); i++) {\n            if (i != firstIndex && i != lastIndex) {\n                result.append(s.charAt(i));\n            }\n        }\n        return result.toString();\n    }\n}", "human_rating": 4.0, "metadata": {}}, {"task_id": "MBJP/12", "source": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport java.math.*;\n\nclass SortMatrix {\n    /**\n     * * Write a function to sort a given matrix in ascending order according to the sum of its rows.\n     *\n     * > sortMatrix([[1, 2, 3], [2, 4, 5], [1, 1, 1]])\n     * [[1, 1, 1], [1, 2, 3], [2, 4, 5]]\n     * > sortMatrix([[1, 2, 3], [-2, 4, -5], [1, -1, 1]])\n     * [[-2, 4, -5], [1, -1, 1], [1, 2, 3]]\n     * > sortMatrix([[5, 8, 9], [6, 4, 3], [2, 1, 4]])\n     * [[2, 1, 4], [6, 4, 3], [5, 8, 9]]\n     */\n    public static List<List<Integer>> sortMatrix(List<List<Integer>> m) {\n        if (m == null || m.size() == 0) {\n            return m;\n        }\n        List<List<Integer>> o = new ArrayList<>();\n        for (int i = 0; i < m.size(); i++) {\n            o.add(m.get(i));\n        }\n        for (int x = 0; x < o.size(); x++) {\n            for (int y = 0; y < o.size() - 1; y++) {\n                int a = 0, b = 0;\n                List<Integer> dx = o.get(y);\n                List<Integer> dy = o.get(y + 1);\n                for (Integer num : dx) {\n                    a += num;\n                }\n                for (Integer num : dy) {\n                    b += num;\n                }\n                if (a > b) {\n                    List<Integer> temp = o.get(y);\n                    o.set(y, o.get(y + 1));\n                    o.set(y + 1, temp);\n                }\n            }\n        }\n        return o;\n    }\n}", "human_rating": 2.0, "metadata": {}}, {"task_id": "MBJP/14", "source": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport java.math.*;\n\nclass FindVolume {\n    /**\n     * * Write a Java function to find the volume of a triangular prism.\n     *\n     * > findVolume(10, 8, 6)\n     * 240\n     * > findVolume(3, 2, 2)\n     * 6\n     * > findVolume(1, 2, 1)\n     * 1\n     */\n    public static int findVolume(int l, int b, int h) {\n        // Calculate the area of the triangular base\n        int baseArea = (b * h) / 2;\n        // Calculate the volume by multiplying base area with length\n        int volume = baseArea * l;\n        return volume;\n    }\n}", "human_rating": 4.5, "metadata": {}}, {"task_id": "MBJP/17", "source": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport java.math.*;\n\nclass SquarePerimeter {\n    /**\n     * * Write a function to find the perimeter of a square.\n     *\n     * > squarePerimeter(10)\n     * 40\n     * > squarePerimeter(5)\n     * 20\n     * > squarePerimeter(4)\n     * 16\n     */\n    public static int squarePerimeter(int a) {\n        int b = a;\n        int c = 0;\n        for (int i = 0; i < 4; i++) {\n            c += b;\n            int d = b - 1;\n            b = d + 1;\n        }\n        return c;\n    }\n}", "human_rating": 2.0, "metadata": {}}, {"task_id": "MBJP/18", "source": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport java.math.*;\n\nclass RemoveDirtyChars {\n    /**\n     * * Write a function to remove characters from the first string which are present in the second string.\n     *\n     * > removeDirtyChars(\"probasscurve\", \"pros\")\n     * \"bacuve\"\n     * > removeDirtyChars(\"digitalindia\", \"talent\")\n     * \"digiidi\"\n     * > removeDirtyChars(\"exoticmiles\", \"toxic\")\n     * \"emles\"\n     */\n    public static String removeDirtyChars(String string, String secondString) {\n        StringBuilder sb = new StringBuilder();\n        for (int i = 0; i < string.length(); i++) {\n            char ch = string.charAt(i);\n            boolean flag = false;\n            int k = 0;\n            while (k < secondString.length()) {\n                if (ch == secondString.charAt(k)) {\n                    flag = true;\n                }\n                k++;\n            }\n            if (!flag) {\n                sb.append(ch);\n            }\n        }\n        return sb.toString();\n    }\n}", "human_rating": 4.5, "metadata": {}}, {"task_id": "MBJP/19", "source": "import java.util.*;\n\nclass TestDuplicate {\n    /**\n     * * Write a function to find whether a given array of integers contains any duplicate element.\n     *\n     * > testDuplicate([1, 2, 3, 4, 5])\n     * false\n     * > testDuplicate([1, 2, 3, 4, 4])\n     * true\n     * > testDuplicate([1, 1, 2, 2, 3, 3, 4, 4, 5])\n     * true\n     */\n    public static Boolean testDuplicate(List<Integer> arraynums) {\n        Set<Integer> seen = new HashSet<>();\n        for (Integer num : arraynums) {\n            if (seen.contains(num)) {\n                return true;\n            }\n            seen.add(num);\n        }\n        return false;\n    }\n}", "human_rating": 5.0, "metadata": {}}, {"task_id": "MBJP/2", "source": "import java.util.*;\n\nclass SimilarElements {\n    /**\n     * * Write a function to find the similar elements from the given two tuple lists.\n     *\n     * > similarElements([3, 4, 5, 6], [5, 7, 4, 10])\n     * [4, 5]\n     * > similarElements([1, 2, 3, 4], [5, 4, 3, 7])\n     * [3, 4]\n     * > similarElements([11, 12, 14, 13], [17, 15, 14, 13])\n     * [13, 14]\n     */\n    public static List<Integer> similarElements(List<Integer> testTup1, List<Integer> testTup2) {\n        Set<Integer> set1 = new HashSet<>(testTup1);\n        List<Integer> result = new ArrayList<>();\n        for (Integer num : testTup2) {\n            if (set1.contains(num)) {\n                result.add(num);\n            }\n        }\n        Collections.sort(result);\n        return result;\n    }\n}", "human_rating": 4.5, "metadata": {}}, {"task_id": "MBJP/21", "source": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport java.math.*;\n\nclass MultiplesOfNum {\n    /**\n     * * Write a function to find m number of multiples of n.\n     *\n     * > multiplesOfNum(4, 3)\n     * [3, 6, 9, 12]\n     * > multiplesOfNum(2, 5)\n     * [5, 10]\n     * > multiplesOfNum(9, 2)\n     * [2, 4, 6, 8, 10, 12, 14, 16, 18]\n     */\n    public static List<Integer> multiplesOfNum(int m, int n) {\n        List<Integer> qwe = new ArrayList<>();\n        int uio = 0;\n        int zxz = 1;\n        while (zxz <= m) {\n            uio = n * zxz;\n            qwe.add(uio);\n            zxz++;\n        }\n        return qwe;\n    }\n}", "human_rating": 2.5, "metadata": {}}, {"task_id": "MBJP/22", "source": "import java.util.*;\n\nclass FindFirstDuplicate {\n    /**\n     * * Write a function to find the first duplicate element in a given array of integers.\n     *\n     * > findFirstDuplicate([1, 2, 3, 4, 4, 5])\n     * 4\n     * > findFirstDuplicate([1, 2, 3, 4])\n     * -1\n     * > findFirstDuplicate([1, 1, 2, 3, 3, 2, 2])\n     * 1\n     */\n    public static int findFirstDuplicate(List<Integer> nums) {\n        Set<Integer> seen = new HashSet<>();\n        for (Integer num : nums) {\n            if (seen.contains(num)) {\n                return num;\n            } else {\n                seen.add(num);\n            }\n        }\n        return -1;\n    }\n}", "human_rating": 5.0, "metadata": {}}, {"task_id": "MBJP/3", "source": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport java.math.*;\n\nclass IsNotPrime {\n    /**\n     * * Write a Java function to identify non-prime numbers.\n     *\n     * > isNotPrime(2)\n     * false\n     * > isNotPrime(10)\n     * true\n     * > isNotPrime(35)\n     * true\n     */\n    public static Boolean isNotPrime(int n) {\n        if (n <= 1) {\n            return true;\n        }\n        for (int i = 2; i <= Math.sqrt(n); i++) {\n            if (n % i == 0) {\n                return true;\n            }\n        }\n        return false;\n    }\n}", "human_rating": 5.0, "metadata": {}}, {"task_id": "MBJP/4", "source": "import java.util.*;\n\nclass HeapQueueLargest {\n    /**\n     * * Write a function to find the largest integers from a given list of numbers using heap queue algorithm.\n     *\n     * > heapQueueLargest([25, 35, 22, 85, 14, 65, 75, 22, 58], 3)\n     * [85, 75, 65]\n     * > heapQueueLargest([25, 35, 22, 85, 14, 65, 75, 22, 58], 2)\n     * [85, 75]\n     * > heapQueueLargest([25, 35, 22, 85, 14, 65, 75, 22, 58], 5)\n     * [85, 75, 65, 58, 35]\n     */\n    public static List<Integer> heapQueueLargest(List<Integer> nums, int n) {\n        PriorityQueue<Integer> minHeap = new PriorityQueue<>();\n        for (Integer num : nums) {\n            if (minHeap.size() < n) {\n                minHeap.offer(num);\n            } else if (num > minHeap.peek()) {\n                minHeap.poll();\n                minHeap.offer(num);\n            }\n        }\n        List<Integer> result = new ArrayList<>(minHeap);\n        result.sort(Collections.reverseOrder());\n        return result;\n    }\n}", "human_rating": 3.0, "metadata": {}}, {"task_id": "MBJP/6", "source": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport java.math.*;\n\nclass DifferAtOneBitPos {\n    /**\n     * * Write a Java function to check whether the two numbers differ at one bit position only or not.\n     *\n     * > differAtOneBitPos(13, 9)\n     * true\n     * > differAtOneBitPos(15, 8)\n     * false\n     * > differAtOneBitPos(2, 4)\n     * false\n     */\n    public static Boolean differAtOneBitPos(int a, int b) {\n        int xor = a ^ b;\n        // Check if xor is a power of two (only one bit set)\n        return xor != 0 && (xor & (xor - 1)) == 0;\n    }\n}", "human_rating": 2.5, "metadata": {}}, {"task_id": "MBJP/7", "source": "import java.util.*;\nimport java.util.regex.*;\n\nclass FindCharLong {\n    /**\n     * * Write a function to find all words which are at least 4 characters long in a string by using regex.\n     *\n     * > findCharLong(\"Please move back to stream\")\n     * [\"Please\", \"move\", \"back\", \"stream\"]\n     * > findCharLong(\"Jing Eco and Tech\")\n     * [\"Jing\", \"Tech\"]\n     * > findCharLong(\"Jhingai wulu road Zone 3\")\n     * [\"Jhingai\", \"wulu\", \"road\", \"Zone\"]\n     */\n    public static List<String> findCharLong(String text) {\n        List<String> result = new ArrayList<>();\n        Pattern pattern = Pattern.compile(\"\\\\\\\\b\\\\\\\\w{4,}\\\\\\\\b\");\n        Matcher matcher = pattern.matcher(text);\n        while (matcher.find()) {\n            result.add(matcher.group());\n        }\n        return result;\n    }\n}", "human_rating": 3.5, "metadata": {}}, {"task_id": "MBJP/8", "source": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport java.math.*;\n\nclass SquareNums {\n    /**\n     * * Write a function to find squares of individual elements in a list using lambda function.\n     *\n     * > squareNums([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])\n     * [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n     * > squareNums([10, 20, 30])\n     * [100, 400, 900]\n     * > squareNums([12, 15])\n     * [144, 225]\n     */\n    public static List<Integer> squareNums(List<Integer> nums) {\n        List<Integer> r = new ArrayList<>();\n        nums.stream().forEach(n -> {\n            int temp = 0;\n            int a = n;\n            int b = 0;\n            int c = 0;\n            boolean d = false;\n            for (int i = 0; i < 10; i++) {\n                if (a == 0) {\n                    break;\n                }\n                a = a / 10;\n            }\n            for (int i = 0; i < 3; i++) {\n                temp = n * n;\n                b = temp;\n                c = b;\n            }\n            int qwe = 0;\n            while (qwe < 1) {\n                int p = n * n;\n                r.add(p);\n                qwe++;\n            }\n        });\n        return r;\n    }\n}", "human_rating": 1.0, "metadata": {}}, {"task_id": "MBJP/9", "source": "import java.io.*;\nimport java.lang.*;\nimport java.util.*;\nimport java.math.*;\n\nclass FindRotations {\n    /**\n     * * Write a Java function to find the minimum number of rotations required to get the same string.\n     *\n     * > findRotations(\"aaaa\")\n     * 1\n     * > findRotations(\"ab\")\n     * 2\n     * > findRotations(\"abc\")\n     * 3\n     */\n    public static int findRotations(String str) {\n        if (str == null || str.length() == 0) {\n            return 0;\n        }\n        int r = 0;\n        String b = str;\n        String c = \"\";\n        while (r < 10000) {\n            StringBuilder sb = new StringBuilder();\n            if (str.length() > 0) {\n                sb.append(str.substring(1));\n                sb.append(str.charAt(0));\n            }\n            c = sb.toString();\n            if (c.equals(str)) {\n                break;\n            } else {\n                str = c;\n                r++;\n            }\n        }\n        int maxB = Integer.MIN_VALUE;\n        int maxIndex = -1;\n        for (int i = 0; i < b.length(); i++) {\n            int count = 0;\n            for (int j = 0; j < b.length(); j++) {\n                if (b.charAt(j) == b.charAt(i)) {\n                    count++;\n                }\n            }\n            if (count > maxB) {\n                maxB = count;\n                maxIndex = i;\n            }\n        }\n        int result = b.length() - maxB + 1;\n        return result;\n    }\n}", "human_rating": 1.5, "metadata": {}}]}