id stringlengths 28 30 | content stringlengths 701 6k |
|---|---|
humaneval-x-java_data_Java_0 | Check if in given list of numbers, are any two numbers closer to each other than given threshold.
>>> hasCloseElements(Arrays.asList(1.0, 2.0, 3.0), 0.5)
false
>>> hasCloseElements(Arrays.asList(1.0, 2.8, 3.0, 4.0, 5.0, 2.0), 0.3)
true
public class Main {
public static void main(String[] args) ... |
humaneval-x-java_data_Java_1 | Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
separate those group into separate strings and return the list of those.
Separate groups are balanced (each open brace is properly closed) and not nested within each other
Ignore any spaces in the input ... |
humaneval-x-java_data_Java_2 | Given a positive floating point number, it can be decomposed into
and integer part (largest integer smaller than given number) and decimals
(leftover part always smaller than 1).
Return the decimal part of the number.
>>> truncateNumber(3.5)
0.5
public class Main {
public static void main(... |
humaneval-x-java_data_Java_3 | You're given a list of deposit and withdrawal operations on a bank account that starts with
zero balance. Your task is to detect if at any point the balance of account fallls below zero, and
at that point function should return True. Otherwise it should return False.
>>> belowZero(Arrays.asList(1, 2, 3)... |
humaneval-x-java_data_Java_4 | For a given list of input numbers, calculate Mean Absolute Deviation
around the mean of this dataset.
Mean Absolute Deviation is the average absolute difference between each
element and a centerpoint (mean in this case):
MAD = average | x - x_mean |
>>> meanAbsoluteDeviation(Arrays.asList(1.0, 2... |
humaneval-x-java_data_Java_5 | Insert a number 'delimeter' between every two consecutive elements of input list `numbers'
>>> intersperse(List.of(), 4)
[]
>>> intersperse(Arrays.asList(1, 2, 3), 4)
[1, 4, 2, 4, 3]
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<B... |
humaneval-x-java_data_Java_6 | Input to this function is a string represented multiple groups for nested parentheses separated by spaces.
For each of the group, output the deepest level of nesting of parentheses.
E.g. (()()) has maximum two levels of nesting while ((())) has three.
>>> parseNestedParens("(()()) ((())) () ((())()())"... |
humaneval-x-java_data_Java_7 | Filter an input list of strings only for ones that contain given substring
>>> filterBySubstring(List.of(), "a")
[]
>>> filterBySubstring(Arrays.asList("abc", "bacd", "cde", "array"), "a")
["abc", "bacd", "array"]
public class Main {
public static void main(String[] args) {
Solution s =... |
humaneval-x-java_data_Java_8 | For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.
Empty sum should be equal to 0 and empty product should be equal to 1.
>>> sumProduct(List.of())
[0, 1]
>>> sumProduct(Arrays.asList(1, 2, 3, 4))
[10, 24]
public class Main {
public... |
humaneval-x-java_data_Java_9 | From a given list of integers, generate a list of rolling maximum element found until given moment
in the sequence.
>>> rollingMax(Arrays.asList(1, 2, 3, 2, 3, 4, 2))
[1, 2, 3, 3, 3, 4, 4]
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List... |
humaneval-x-java_data_Java_10 | Find the shortest palindrome that begins with a supplied string.
Algorithm idea is simple:
- Find the longest postfix of supplied string that is a palindrome.
- Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
>>> makePalindrome("")
""
>>> ... |
humaneval-x-java_data_Java_11 | Input are two strings a and b consisting only of 1s and 0s.
Perform binary XOR on these inputs and return result also as a string.
>>> stringXor("010", "110")
"100"
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arra... |
humaneval-x-java_data_Java_12 | Out of list of strings, return the longest one. Return the first one in case of multiple
strings of the same length. Return None in case the input list is empty.
>>> longest(List.of())
Optional.empty
>>> longest(Arrays.asList("a", "b", "c"))
Optional[a]
>>> longest(Arrays.asList("a", "bb", "... |
humaneval-x-java_data_Java_13 | Return a greatest common divisor of two integers a and b
>>> greatestCommonDivisor(3, 5)
1
>>> greatestCommonDivisor(25, 15)
5
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arrays.asList(
s.great... |
humaneval-x-java_data_Java_14 | Return list of all prefixes from shortest to longest of the input string
>>> allPrefixes("abc")
["a", "ab", "abc"]
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arrays.asList(
s.allPrefixes("").equals(Li... |
humaneval-x-java_data_Java_15 | Return a string containing space-delimited numbers starting from 0 upto n inclusive.
>>> stringSequence(0)
"0"
>>> stringSequence(5)
"0 1 2 3 4 5"
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arrays.asList(
... |
humaneval-x-java_data_Java_16 | Given a string, find out how many distinct characters (regardless of case) does it consist of
>>> countDistinctCharacters("xyzXYZ")
3
>>> countDistinctCharacters("Jerry")
4
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> co... |
humaneval-x-java_data_Java_17 | Input to this function is a string representing musical notes in a special ASCII format.
Your task is to parse this string and return list of integers corresponding to how many beats does each
not last.
Here is a legend:
"o" - whole note, lasts four beats
"o|" - half note, lasts two beats
"... |
humaneval-x-java_data_Java_18 | Find how many times a given substring can be found in the original string. Count overlaping cases.
>>> howManyTimes("", "a")
0
>>> howManyTimes("aaa", "a")
3
>>> howManyTimes("aaaa", "aa")
3
public class Main {
public static void main(String[] args) {
Solution s = new Solution()... |
humaneval-x-java_data_Java_19 | Input is a space-delimited string of numberals from 'zero' to 'nine'.
Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'.
Return the string with numbers sorted from smallest to largest
>>> sortNumbers("three one five")
"one three five"
public class M... |
humaneval-x-java_data_Java_20 | From a supplied list of numbers (of length at least two) select and return two that are the closest to each
other and return them in order (smaller number, larger number).
>>> findClosestElements(Arrays.asList(1.0, 2.0, 3.0, 4.0, 5.0, 2.2))
[2.0, 2.2]
>>> findClosestElements(Arrays.asList(1.0, 2.0, ... |
humaneval-x-java_data_Java_21 | Given list of numbers (of at least two elements), apply a linear transform to that list,
such that the smallest number will become 0 and the largest will become 1
>>> rescaleToUnit(Arrays.asList(1.0, 2.0, 3.0, 4.0, 5.0))
[0.0, 0.25, 0.5, 0.75, 1.0]
public class Main {
public static void main(String... |
humaneval-x-java_data_Java_22 | Filter given list of any values only for integers
>>> filter_integers(Arrays.asList('a', 3.14, 5))
[5]
>>> filter_integers(Arrays.asList(1, 2, 3, "abc", Map.of(), List.of()))
[1, 2, 3]
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List... |
humaneval-x-java_data_Java_23 | Return length of given string
>>> strlen("")
0
>>> strlen("abc")
3
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arrays.asList(
s.strlen("") == 0,
s.strlen("x") == 1,
... |
humaneval-x-java_data_Java_24 | For a given number n, find the largest number that divides n evenly, smaller than n
>>> largestDivisor(15)
5
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arrays.asList(
s.largestDivisor(3) == 1,
... |
humaneval-x-java_data_Java_25 | Return list of prime factors of given integer in the order from smallest to largest.
Each of the factors should be listed number of times corresponding to how many times it appeares in factorization.
Input number should be equal to the product of all factors
>>> factorize(8)
[2, 2, 2]
>>> factor... |
humaneval-x-java_data_Java_26 | From a list of integers, remove all elements that occur more than once.
Keep order of elements left the same as in the input.
>>> removeDuplicates(Array.asList(1, 2, 3, 2, 4))
[1, 3, 4]
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Bo... |
humaneval-x-java_data_Java_27 | For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
>>> flipCase("Hello")
"hELLO"
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arrays.asList(
Objects.equals(s.flipCase... |
humaneval-x-java_data_Java_28 | Concatenate list of strings into a single string
>>> concatenate(List.of())
""
>>> concatenate(Arrays.asList("a", "b", "c"))
"abc"
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arrays.asList(
Obj... |
humaneval-x-java_data_Java_29 | Filter an input list of strings only for ones that start with a given prefix.
>>> filterByPrefix(List.of(), "a")
[]
>>> filterByPrefix(Arrays.asList("abc", "bcd", "cde", "array"), "a")
["abc", "array"]
public class Main {
public static void main(String[] args) {
Solution s = new Solutio... |
humaneval-x-java_data_Java_30 | Return only positive numbers in the list.
>>> getPositive(Arrays.asList(-1, 2, -4, 5, 6))
[2, 5, 6]
>>> getPositive(Arrays.asList(5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10))
[5, 3, 2, 3, 9, 123, 1]
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
... |
humaneval-x-java_data_Java_31 | Return true if a given number is prime, and false otherwise.
>>> isPrime(6)
false
>>> isPrime(101)
true
>>> isPrime(11)
true
>>> isPrime(13441)
true
>>> isPrime(61)
true
>>> isPrime(4)
false
>>> isPrime(1)
false
public class Main {
public static void main... |
humaneval-x-java_data_Java_32 | xs are coefficients of a polynomial.
findZero find x such that poly(x) = 0.
findZero returns only only zero point, even if there are many.
Moreover, findZero only takes list xs having even number of coefficients
and largest non zero coefficient as it guarantees
a solution.
>>> findZero(Array... |
humaneval-x-java_data_Java_33 | This function takes a list l and returns a list l' such that
l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal
to the values of the corresponding indicies of l, but sorted.
>>> sortThird(Arrays.asList(1, 2, 3))
... |
humaneval-x-java_data_Java_34 | Return sorted unique elements in a list
>>> unique(Arrays.asList(5, 3, 5, 2, 3, 3, 9, 0, 123))
[0, 2, 3, 5, 9, 123]
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arrays.asList(
s.unique(new ArrayList<>(A... |
humaneval-x-java_data_Java_35 | Return maximum element in the list.
>>> maxElement(Arrays.asList(1, 2, 3))
3
>>> maxElement(Arrays.asList(5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10))
123
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arrays.asList(
... |
humaneval-x-java_data_Java_36 | Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
>>> fizzBuzz(50)
0
>>> fizzBuzz(78)
2
>>> fizzBuzz(79)
3
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correc... |
humaneval-x-java_data_Java_37 | This function takes a list l and returns a list l' such that
l' is identical to l in the odd indicies, while its values at the even indicies are equal
to the values of the even indicies of l, but sorted.
>>> sortEven(Arrays.asList(1, 2, 3))
[1, 2, 3]
>>> sortEven(Arrays.asList(5, 6, 3, 4))
[... |
humaneval-x-java_data_Java_38 | takes as input string encoded with encodeCyclic function. Returns decoded string.
public class Main {
static char[] letters = "abcdefghijklmnopqrstuvwxyz".toCharArray();
static Random rand = new Random(42);
public static String random_string(int length) {
StringBuilder sb = new StringBuilder();... |
humaneval-x-java_data_Java_39 | primeFib returns n-th number that is a Fibonacci number and it's also prime.
>>> primeFib(1)
2
>>> primeFib(2)
3
>>> primeFib(3)
5
>>> primeFib(4)
13
>>> primeFib(5)
89
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
... |
humaneval-x-java_data_Java_40 | triplesSumToZero takes a list of integers as an input.
it returns True if there are three distinct elements in the list that
sum to zero, and False otherwise.
>>> triplesSumToZero(Arrays.asList(1, 3, 5, 0))
false
>>> triplesSumToZero(Arrays.asList(1, 3, -2, 1))
true
>>> triplesSumToZero... |
humaneval-x-java_data_Java_41 | Imagine a road that's a perfectly straight infinitely long line.
n cars are driving left to right; simultaneously, a different set of n cars
are driving right to left. The two sets of cars start out being very far from
each other. All cars move in the same speed. Two cars are said to collide
wh... |
humaneval-x-java_data_Java_42 | Return list with elements incremented by 1.
>>> incrList(Arrays.asList(1, 2, 3))
[2, 3, 4]
>>> incrList(Arrays.asList(5, 3, 5, 2, 3, 3, 9, 0, 123))
[6, 4, 6, 3, 4, 4, 10, 1, 124]
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boole... |
humaneval-x-java_data_Java_43 | pairsSumToZero takes a list of integers as an input.
it returns True if there are two distinct elements in the list that
sum to zero, and False otherwise.
>>> pairsSumToZero(Arrays.asList(1, 3, 5, 0))
false
>>> pairsSumToZero(Arrays.asList(1, 3, -2, 1))
false
>>> pairsSumToZero(Arrays.as... |
humaneval-x-java_data_Java_44 | Change numerical base of input number x to base.
return string representation after the conversion.
base numbers are less than 10.
>>> changeBase(8, 3)
"22"
>>> changeBase(8, 2)
"1000"
>>> changeBase(7, 2)
"111"
public class Main {
public static void main(String[] args) {
... |
humaneval-x-java_data_Java_45 | Given length of a side and high return area for a triangle.
>>> triangleArea(5, 3)
7.5
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arrays.asList(
s.triangleArea(5, 3) == 7.5,
s.triangle... |
humaneval-x-java_data_Java_46 | The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
fib4(0) -> 0
fib4(1) -> 0
fib4(2) -> 2
fib4(3) -> 0
fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4).
Please write a function to efficiently compute the n-th element of the fib4 numbe... |
humaneval-x-java_data_Java_47 | Return median of elements in the list l.
>>> median(Arrays.asList(3, 1, 2, 4, 5))
3
>>> median(Arrays.asList(-10, 4, 6, 1000, 10, 20))
15.0
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arrays.asList(
... |
humaneval-x-java_data_Java_48 | Checks if given string is a palindrome
>>> isPalindrome("")
true
>>> isPalindrome("aba")
true
>>> isPalindrome("aaaaa")
true
>>> isPalindrome("zbcd")
false
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> cor... |
humaneval-x-java_data_Java_49 | Return 2^n modulo p (be aware of numerics).
>>> modp(3, 5)
3
>>> modp(1101, 101)
2
>>> modp(0, 101)
1
>>> modp(3, 11)
8
>>> modp(100, 101)
1
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = ... |
humaneval-x-java_data_Java_50 | takes as input string encoded with encodeShift function. Returns decoded string.
public class Main {
static char[] letters = "abcdefghijklmnopqrstuvwxyz".toCharArray();
static Random rand = new Random(42);
public static String random_string(int length) {
StringBuilder sb = new StringBuilder();... |
humaneval-x-java_data_Java_51 | removeVowels is a function that takes string and returns string without vowels.
>>> removeVowels("")
""
>>> removeVowels("abcdef\nghijklm")
"bcdf\nghjklm"
>>> removeVowels("abcdef")
"bcdf"
>>> removeVowels("aaaaa")
""
>>> removeVowels("aaBAA")
"B"
>>> removeVowels("zbcd")... |
humaneval-x-java_data_Java_52 | Return True if all numbers in the list l are below threshold t.
>>> belowThreshold(Arrays.asList(1, 2, 4, 10), 100)
true
>>> belowThreshold(Arrays.asList(1, 20, 4, 10), 5)
false
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolea... |
humaneval-x-java_data_Java_53 | Add two numbers x and y
>>> add(2, 3)
5
>>> add(5, 7)
12
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
Random rand = new Random(42);
List<Boolean> correct = Arrays.asList(
s.add(0, 1) == 1,
s.add... |
humaneval-x-java_data_Java_54 | Check if two words have the same characters.
>>> sameChars("eabcdzzzz", "dddzzzzzzzddeddabc")
true
>>> sameChars("abcd", "dddddddabc")
true
>>> sameChars("dddddddabc", "abcd")
true
>>> sameChars("eabcd", "dddddddabc")
false
>>> sameChars("abcd", "dddddddabce")
false
>>> s... |
humaneval-x-java_data_Java_55 | Return n-th Fibonacci number.
>>> fib(10)
55
>>> fib(1)
1
>>> fib(8)
21
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arrays.asList(
s.fib(10) == 55,
s.fib(1) == 1,
... |
humaneval-x-java_data_Java_56 | brackets is a string of "<" and ">".
return True if every opening bracket has a corresponding closing bracket.
>>> correctBracketing("<")
false
>>> correctBracketing("<>")
true
>>> correctBracketing("<<><>>")
true
>>> correctBracketing("><<>")
false
public class Main {
... |
humaneval-x-java_data_Java_57 | Return True is list elements are monotonically increasing or decreasing.
>>> monotonic(Arrays.asList(1, 2, 4, 20))
true
>>> monotonic(Arrays.asList(1, 20, 4, 10))
false
>>> monotonic(Arrays.asList(4, 1, 0, -10))
true
public class Main {
public static void main(String[] args) {
S... |
humaneval-x-java_data_Java_58 | Return sorted unique common elements for two lists.
>>> common(Arrays.asList(1, 4, 3, 34, 653, 2, 5), Arrays.asList(5, 7, 1, 5, 9, 653, 121))
[1, 5, 653]
>>> common(Arrays.asList(5, 3, 2, 8), Arrays.asList(3, 2))
[2, 3]
public class Main {
public static void main(String[] args) {
Soluti... |
humaneval-x-java_data_Java_59 | Return the largest prime factor of n. Assume n > 1 and is not a prime.
>>> largestPrimeFactor(13195)
29
>>> largestPrimeFactor(2048)
2
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arrays.asList(
... |
humaneval-x-java_data_Java_60 | sumToN is a function that sums numbers from 1 to n.
>>> sumToN(30)
465
>>> sumToN(100)
5050
>>> sumToN(5)
15
>>> sumToN(10)
55
>>> sumToN(1)
1
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct ... |
humaneval-x-java_data_Java_61 | brackets is a string of "(" and ")".
return True if every opening bracket has a corresponding closing bracket.
>>> correctBracketing("(")
false
>>> correctBracketing("()")
true
>>> correctBracketing("(()())")
true
>>> correctBracketing(")(()")
false
public class Main {
publ... |
humaneval-x-java_data_Java_62 | xs represent coefficients of a polynomial.
xs[0] + xs[1] * x + xs[2] * x^2 + ....
Return derivative of this polynomial in the same form.
>>> derivative(Arrays.asList(3, 1, 2, 4, 5))
[1, 4, 12, 20]
>>> derivative(Arrays.asList(1, 2, 3]))
[2, 6]
public class Main {
public static void mai... |
humaneval-x-java_data_Java_63 | The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows:
fibfib(0) == 0
fibfib(1) == 0
fibfib(2) == 1
fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3).
Please write a function to efficiently compute the n-th element of the fibfib number sequence.... |
humaneval-x-java_data_Java_64 | Write a function vowelsCount which takes a string representing
a word as input and returns the number of vowels in the string.
Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a
vowel, but only when it is at the end of the given word.
Example:
>>> vowelsCount("abcde")
2
... |
humaneval-x-java_data_Java_65 | Circular shift the digits of the integer x, shift the digits right by shift
and return the result as a string.
If shift > number of digits, return digits reversed.
>>> circularShift(12, 1)
"21"
>>> circularShift(12, 2)
"12"
public class Main {
public static void main(String[] args) {
... |
humaneval-x-java_data_Java_66 | Write a function that takes a string as input and returns the sum of the upper characters only'
ASCII codes.
Examples:
digitSum("") => 0
digitSum("abAB") => 131
digitSum("abcCd") => 67
digitSum("helloE") => 69
digitSum("woArBld") => 131
digitSum("aAaaaXa") =>... |
humaneval-x-java_data_Java_67 | In this task, you will be given a string that represents a number of apples and oranges
that are distributed in a basket of fruit this basket contains
apples, oranges, and mango fruits. Given the string that represents the total number of
the oranges and apples and an integer that represent the total nu... |
humaneval-x-java_data_Java_68 | "Given an array representing a branch of a tree that has non-negative integer nodes
your task is to pluck one of the nodes and return it.
The plucked node should be the node with the smallest even value.
If multiple nodes with the same smallest even value are found return the node that has smallest inde... |
humaneval-x-java_data_Java_69 | You are given a non-empty list of positive integers. Return the greatest integer that is greater than
zero, and has a frequency greater than or equal to the value of the integer itself.
The frequency of an integer is the number of times it appears in the list.
If no such a value exist, return -1.
Ex... |
humaneval-x-java_data_Java_70 | Given list of integers, return list in strange order.
Strange sorting, is when you start with the minimum value,
then maximum of the remaining integers, then minimum and so on.
Examples:
strangeSortList(Arrays.asList(1, 2, 3, 4)) == Arrays.asList(1, 4, 2, 3)
strangeSortList(Arrays.asList(5, 5, ... |
humaneval-x-java_data_Java_71 | Given the lengths of the three sides of a triangle. Return the area of
the triangle rounded to 2 decimal points if the three sides form a valid triangle.
Otherwise return -1
Three sides make a valid triangle when the sum of any two sides is greater
than the third side.
Example:
triangleArea(... |
humaneval-x-java_data_Java_72 | Write a function that returns True if the object q will fly, and False otherwise.
The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w.
Example:
willItFly(Arrays.asList(1, 2), 5) -> false
# 1+2 is less than... |
humaneval-x-java_data_Java_73 | Given an array arr of integers, find the minimum number of elements that
need to be changed to make the array palindromic. A palindromic array is an array that
is read the same backwards and forwards. In one change, you can change one element to any other element.
For example:
smallestChange(Arrays... |
humaneval-x-java_data_Java_74 | Write a function that accepts two lists of strings and returns the list that has
total number of chars in the all strings of the list less than the other list.
if the two lists have the same number of chars, return the first list.
Examples
totalMatch(Arrays.asList(), Arrays.asList()) -> []
tot... |
humaneval-x-java_data_Java_75 | Write a function that returns true if the given number is the multiplication of 3 prime numbers
and false otherwise.
Knowing that (a) is less then 100.
Example:
isMultiplyPrime(30) == true
30 = 2 * 3 * 5
public class Main {
public static void main(String[] args) {
Solution s = new S... |
humaneval-x-java_data_Java_76 | Your task is to write a function that returns true if a number x is a simple
power of n and false in other cases.
x is a simple power of n if n**int=x
For example:
isSimplePower(1, 4) => true
isSimplePower(2, 2) => true
isSimplePower(8, 2) => true
isSimplePower(3, 2) => false
isSimpl... |
humaneval-x-java_data_Java_77 | Write a function that takes an integer a and returns true
if this ingeger is a cube of some integer number.
Note: you may assume the input is always valid.
Examples:
iscube(1) ==> true
iscube(2) ==> false
iscube(-1) ==> true
iscube(64) ==> true
iscube(0) ==> true
iscube(180) ==> ... |
humaneval-x-java_data_Java_78 | You have been tasked to write a function that receives
a hexadecimal number as a string and counts the number of hexadecimal
digits that are primes (prime number, or a prime, is a natural number
greater than 1 that is not a product of two smaller natural numbers).
Hexadecimal digits are 0, 1, 2, 3, ... |
humaneval-x-java_data_Java_79 | You will be given a number in decimal form and your task is to convert it to
binary format. The function should return a string, with each character representing a binary
number. Each character in the string will be '0' or '1'.
There will be an extra couple of characters 'db' at the beginning and at th... |
humaneval-x-java_data_Java_80 | You are given a string s.
Your task is to check if the string is happy or not.
A string is happy if its length is at least 3 and every 3 consecutive letters are distinct
For example:
isHappy(a) => false
isHappy(aa) => false
isHappy(abcd) => true
isHappy(aabb) => false
isHappy(adb) =>... |
humaneval-x-java_data_Java_81 | It is the last week of the semester and the teacher has to give the grades
to students. The teacher has been making her own algorithm for grading.
The only problem is, she has lost the code she used for grading.
She has given you a list of GPAs for some students and you have to write
a function that... |
humaneval-x-java_data_Java_82 | Write a function that takes a string and returns true if the string
length is a prime number or false otherwise
Examples
primeLength("Hello") == true
primeLength("abcdcba") == true
primeLength("kittens") == true
primeLength("orange") == false
public class Main {
public static void main(... |
humaneval-x-java_data_Java_83 | Given a positive integer n, return the count of the numbers of n-digit
positive integers that start or end with 1.
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arrays.asList(
s.startsOneEnds(1) == 1,
... |
humaneval-x-java_data_Java_84 | Given a positive integer N, return the total sum of its digits in binary.
Example
For N = 1000, the sum of digits will be 1 the output should be "1".
For N = 150, the sum of digits will be 6 the output should be "110".
For N = 147, the sum of digits will be 12 the output should be "1100... |
humaneval-x-java_data_Java_85 | Given a non-empty list of integers lst. add the even elements that are at odd indices..
Examples:
add(Arrays.asList(4, 2, 6, 7)) ==> 2
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Boolean> correct = Arrays.asList(
s.... |
humaneval-x-java_data_Java_86 | Write a function that takes a string and returns an ordered version of it.
Ordered version of string, is a string where all words (separated by space)
are replaced by a new word where all the characters arranged in
ascending order based on ascii value.
Note: You should keep the order of words and bl... |
humaneval-x-java_data_Java_87 | You are given a 2 dimensional data, as a nested lists,
which is similar to matrix, however, unlike matrices,
each row may contain a different number of columns.
Given lst, and integer x, find integers x in the list,
and return list of lists, [[x1, y1], [x2, y2] ...] such that
each list is a coor... |
humaneval-x-java_data_Java_88 | Given an array of non-negative integers, return a copy of the given array after sorting,
you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
or sort it in descending order if the sum( first index value, last index value) is even.
Note:
* don't c... |
humaneval-x-java_data_Java_89 | Create a function encrypt that takes a string as an argument and
returns a string encrypted with the alphabet being rotated.
The alphabet should be rotated in a manner such that the letters
shift down by two multiplied to two places.
For example:
encrypt("hi") returns "lm"
encrypt("asdfghjkl... |
humaneval-x-java_data_Java_90 | You are given a list of integers.
Write a function nextSmallest() that returns the 2nd smallest element of the list.
Return null if there is no such element.
<p>
nextSmallest(Arrays.asList(1, 2, 3, 4, 5)) == Optional[2]
nextSmallest(Arrays.asList(5, 1, 4, 3, 2)) == Optional[2]
nextSmallest(A... |
humaneval-x-java_data_Java_91 | You'll be given a string of words, and your task is to count the number
of boredoms. A boredom is a sentence that starts with the word "I".
Sentences are delimited by '.', '?' or '!'.
For example:
>>> isBored("Hello world")
0
>>> isBored("The sky is blue. The sun is shining. I love this wea... |
humaneval-x-java_data_Java_92 | Create a function that takes 3 numbers.
Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers.
Returns false in any other cases.
Examples
anyInt(5, 2, 7) -> true
anyInt(3, 2, 2) -> false
anyInt(3, -2, 1) -> true
anyInt(3.6, -2.2, 2) -> ... |
humaneval-x-java_data_Java_93 | Write a function that takes a message, and encodes in such a
way that it swaps case of all letters, replaces all vowels in
the message with the letter that appears 2 places ahead of that
vowel in the english alphabet.
Assume only letters.
Examples:
>>> encode("test")
"TGST"
>>> enco... |
humaneval-x-java_data_Java_94 | You are given a list of integers.
You need to find the largest prime value and return the sum of its digits.
Examples:
For lst = [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] the output should be 10
For lst = [1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1] the output should be 25
For lst = [1,... |
humaneval-x-java_data_Java_95 | Given a map, return True if all keys are strings in lower
case or all keys are strings in upper case, else return False.
The function should return False is the given map is empty.
Examples:
checkDictCase({"a":"apple", "b":"banana"}) should return True.
checkDictCase({"a":"apple", "A":"banana", ... |
humaneval-x-java_data_Java_96 | Implement a function that takes an non-negative integer and returns an array of the first n
integers that are prime numbers and less than n.
for example:
countUpTo(5) => [2,3]
countUpTo(11) => [2,3,5,7]
countUpTo(0) => []
countUpTo(20) => [2,3,5,7,11,13,17,19]
countUpTo(1) => []
coun... |
humaneval-x-java_data_Java_97 | Complete the function that takes two integers and returns
the product of their unit digits.
Assume the input is always valid.
Examples:
multiply(148, 412) should return 16.
multiply(19, 28) should return 72.
multiply(2020, 1851) should return 0.
multiply(14,-15) should return 20.
public... |
humaneval-x-java_data_Java_98 | Given a string s, count the number of uppercase vowels in even indices.
For example:
countUpper("aBCdEf") returns 1
countUpper("abcdefg") returns 0
countUpper("dBBE") returns 0
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
List<Bo... |
humaneval-x-java_data_Java_99 | Create a function that takes a value (string) representing a number
and returns the closest integer to it. If the number is equidistant
from two integers, round it away from zero.
Examples
>>> closest_integer("10")
10
>>> closest_integer("15.3")
15
Note:
Rounding away from zero... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.