Multiple Q
Multiple Q
Multiple Q
Hint use modulo and integer arithmetic to count the number of ones.
2) A Daphne array is an array that contains either all odd numbers or all
even numbers. For example, {2, 4, 2} (only even numbers) and {1, 3,
17, -5} (only odd numbers) are Daphne arrays but {3, 2, 5} is not
because it contains both odd and even numbers. Write a function
named isDaphne that returns 1 if its array argument is a Daphne array.
Otherwise it returns 0.
There are 3 questions on this test. You have 2 hours to finish it. Please do
your own work.
int isNormal(int n)
So {1, 2, 3, 9, 6, 11} and {3, 4, 6, 7, 14, 16}, {1, 2, 3, 4, 10, 11, 13}
and {3, 6, 5, 5, 13, 6, 13} are Filter arrays. The following arrays are
not Filter arrays: {9, 6, 18} (contains 9 but no 11), {4, 7, 13}
(contains both 7 and 13)
There are three questions on this test. You have two hours to complete it.
Please do your own work.
More examples:
isDigitSum(32121,9) returns 0, isDigitSum(13, 6) returns 1,
isDigitSum(3, 3) returns 0
You may assume that there exists a function isPrime that returns 1 if it
argument is a prime, otherwise it returns 0. You do not have to write
this function.
There are three questions on this test. You have two hours to complete it.
Please do your own work. You are not allowed to use any methods or
functions provided by the system unless explicitly stated in the question. In
particular, you are not allowed to convert int to a String or vice-versa.
10) An Evens number is an integer whose digits are all even. For
example 2426 is an Evens number but 3224 is not.
You may assume that a function named isPrime exists that returns 1 if
its int argument is a prime, otherwise it returns 0. You do not have to
write this function! You are allowed to use it.
Examples: {2, 3, 6, 7} is balanced since a[0] and a[2] are even, a[1]
and a[3] are odd. {6, 7, 2, 3, 12} is balanced since a[0], a[2] and a[4]
are even, a[1] and a[3] are odd.
{7, 15, 2, 3} is not balanced since a[0] is odd.
{16, 6, 2, 3} is not balanced since a[1] is even.
There are three questions on this test. You have two hours to complete it.
Please do your own work. You are not allowed to use any methods or
functions provided by the system unless explicitly stated in the question. In
particular, you are not allowed to convert int to a String or vice-versa.
Examples:
hasKSmallFactors(7, 30) is true (since 5*6 = 30 and 5 < 7, 6 < 7).
hasKSmallFactors(6, 14) is false (since the only way to factor 14 is
2*7 = 14 and 7 not less than 6)
hasKSmallFactors(6, 30) is false (since 5*6 = 30, 6 not less than 6; 3 *
10 = 30, 10 not less than 6; 2 * 15 = 30, 15 not less than 6)
Examples:
fill({1,2,3,5, 9, 12,-2,-1}, 3, 10) returns {1,2,3,1,2,3,1,2,3,1}.
fill({4, 2, -3, 12}, 1, 5) returns {4, 4, 4, 4, 4}.
fill({2, 6, 9, 0, -3}, 0, 4) returns null.
There are 3 questions on this test. You have 2 hours to finish it. Please
do your own work. All you need to write is three functions. Please do
not use any string functions. No sorting allowed. No additional arrays
allowed. Try to write a simple, elegant and correct code.
[Lien] Concern: done
[Lien] ok
20) A wave array is defined to an array which does not contain
two even numbers or two odd numbers in adjacent locations. So {7, 2,
9, 10, 5}, {4, 11, 12, 1, 6}, {1, 0, 5} and {2} are all wave arrays. But
{2, 6, 3, 4} is not a wave array because the even numbers 2 and 6 are
adjacent to each other.
So {1, 2, 3, 9, 6, 13} and {3, 4, 6, 7, 13, 15}, {1, 2, 3, 4, 10, 11, 12}
and {3, 6, 9, 5, 7, 13, 6, 17} are Bean arrays. The following arrays are
not Bean arrays:
a. { 9, 6, 18} (contains a 9 but no 13)
b. {4, 7, 16} (contains both a 7 and a 16)
There are three questions on this test. You have two hours to complete it.
Please do your own work. You are not allowed to use any methods or
functions provided by the system unless explicitly stated in the question. In
particular, you are not allowed to convert int to a String or vice-versa.
==Continue
Hint: Use modulo base 10 and integer arithmetic to isolate the digits
of the number.
You may assume that there exists a function isPrime that returns 1 if it
argument is a prime, otherwise it returns 0. You do not have to write
this function.
24) A Meera array is defined to be an array such that for all values
n in the array, the value 2*n is not in the array. So {3, 5, -2} is a
Meera array because 3*2, 5*2 and -2*2 are not in the array. But {8, 3,
4} is not a Meera array because for n=4, 2*n=8 is in the array.
There are three questions on this test. You have two hours to complete it.
Please do your own work. You are not allowed to use any methods or
functions provided by the system unless explicitly stated in the question. In
particular, you are not allowed to convert int to a String or vice-versa.
It is okay if a Bunker array contains more than one value 1 and more
than one prime, so the array {3, 7, 1, 8, 1} is a Bunker array (3 and 7
are the primes).
Write a function named isBunker that returns 1 if its array argument is
a Bunker array and returns 0 otherwise.
Other Nice arrays include {2, 2, 3, 3, 3}, {1, 1, 1, 2, 1, 1} and {0, -1,
1}.
The array {3, 4, 5, 7} is not a Nice array because of the value 7 which
requires that the array contains either the value 6 (7-1) or 8 (7+1) but
neither of these values are in the array.
There are 3 questions on this test. You have two hours to finish it. Please
do your own work. All you need to write is two functions. Please do not
use any string methods. No sorting allowed. No additional data
structures including arrays allowed. Try to write a simple, elegant and
correct code.
29) Consider the prime number 11. Note that 13 is also a prime and
13 – 11 = 2. So, 11 and 13 are known as twin primes. Similarly, 29
and 31 are twin primes. So is 71 and 73. However, there are many
primes for which there is no twin. Examples are 23, 67. A twin array
is defined to an array which every prime that has a twin appear with a
twin. Some examples are
{3, 5, 8, 10, 27}, // 3 and 5 are twins and both are present
{11, 9, 12, 13, 23}, // 11 and 13 are twins and both are present, 23
has no twin
{5, 3, 14, 7, 18, 67}. // 3 and 5 are twins, 5 and 7 are twins, 67 has
no twin
30) Let us define two arrays as “set equal” if every element in one
is also in the other and vice-versa. For example, any two of the
following are equal to one another: {1, 9, 12}, {12, 1, 9}, {9, 1, 12,
1}, {1, 9, 12, 9, 12, 1, 9}. Note that {1, 7, 8} is not set equal to {1, 7,
1} or {1, 7, 6}.
There are 3 questions on this test. You have two hours to finish it. Please
do your own work. All you need to write is two functions. Please do not
use any string methods. No sorting allowed. No additional data
structures including arrays allowed. Try to write a simple, elegant and
correct code.
You may assume that a function named isPrime exists that returns 1 if
its int argument is a prime, otherwise it returns 0. You do **not**
have to write this function! You just have to call it.
34) Two integers are defined to be factor equal, if they have the
same number of factors. For example, integers 10 and 33 are factor
equal because, 10 has four factors: 1, 2, 5, 10 and 33 also has four
factors: 1, 3, 11, 33. On the other hand, 9 and 10 are not factor equal
since 9 has only three factors: 1, 3, 9 and 10 has four factors: 1, 2, 5,
10.
and -4 + 0 + 1 + 0 + 2 + 1 = 0
There are 3 questions on this test. You have two hours to finish it. Please
do your own work. All you need to write is three functions. Please do
not use any string methods. No sorting allowed. No additional data
structures including arrays allowed. Try to write a simple, elegant and
correct code.
37) A Fibonacci number is a number in the sequence 1, 1, 2, 3, 5,
8, 13, 21,…. Note that first two Fibonacci numbers are 1 and any
Fibonacci number other than the first two is the sum of the previous
two Fibonacci numbers. For example, 2 = 1 + 1, 3 = 2 + 1, 5 = 3 + 2
and so on.
38) A Meera array is an array that contains the value 0 if and only
if it contains a prime number. The array {7, 6, 0, 10, 1} is a Meera
array because it contains a prime number (7) and also contains a 0.
The array {6, 10, 1} is a Meera array because it contains no prime
number and also contains no 0.
The array {7, 6, 10} is not a Meera array because it contains a prime
number (7) but does not contain a 0. The array {6, 10, 0} is not a
Meera array because it contains a 0 but does not contain a prime
number.
It is okay if a Meera array contains more than one value 0 and more
than one prime, so the array {3, 7, 0, 8, 0, 5} is a Meera array (3, 5
and 7 are the primes and there are two zeros.).
Other Bean arrays include {2, 2, 3, 3, 3}, {1, 1, 1, 2, 1, 1} and {0, -1,
1}.
The array {3, 4, 5, 7} is not a Bean array because of the value 7 which
requires that the array contains either the value 6 (7-1) or 8 (7+1) but
neither of these values are in the array.