Sei sulla pagina 1di 3

ARICENT TEST PAPER

Question: An array is said to be hollow if it contains 3 or more zeros in the middle that
are preceded and followed by the same number of non-zero elements. Furthermore, all
the zeroes in the array must be in the middle of the array. Write a function
named isHollow that accepts an integer array and returns 1 if it is a hollow array,
otherwise it returns 0.

If you are programming in Java or C#, the function signature is


int isHollow(int[ ] a)

If you are programming in C or C++, the function signature is


int isHollow(int a[ ], int len) where len is the number of elements in the array

Examples:

is
if the input array is Reason
hollow?
{1,2,0,0,0,3,4} yes 2 non-zeros precede and follow 3 zeros in the middle
{1,1,1,1,0,0,0,0,0,2,1,2,18} yes 4 non-zeros precede and follow the 5 zeros in the middle
{1, 2, 0, 0, 3, 4} no There are only 2 zeroes in the middle; at least 3 are required
The number of preceding non-zeros(2) is not equal to the
{1,2,0,0,0,3,4,5} no
number of following non-zeros(3)
The number of preceding non-zeros(3) is not equal to the
{3,8,3,0,0,0,3,3} no
number of following non-zeros(2)
{1,2,0,0,0,3,4,0} no Not all zeros are in the middle
{0,1,2,0,0,0,3,4} no Not all zeros are in the middle
The number of preceding non-zeros is 0 which equals the
{0,0,0} yes number of following non-zeros. And there are three zeros
"in the middle".

Hint: Write three loops. The first counts the number of preceding non-zeros. The
second counts the number of zeros in the middle. The third counts the number of
following non-zeros. Then analyze the results.
Question: Define a flipflop array to be one whose elements alternate between even
and odd values or vice versa. A flipflop array must have at least two elements. For
example {0, 3, 4, -7} and {1, 2, 3, 4} are flipflop arrays but {2, 2, 3, 4}, {1, 2, 3, 3, 4}
and {2} are not.

Write a function called isFlipFlop that returns 1 if its argument is a flipflop array,
otherwise it returns 0.

If you are programming in Java or C#, the function signature is


int isFlipFlop (int [ ] a)

If you are programming in C++ or C, the function signature is


int isFlipFlop (int a [ ], int len) where len is the number of elements in the array.

Question:-A prime number is an integer that is divisible only by 1 and itself.


A rhino number is a prime number whose last digit is 9 and the next prime number
that follows it also ends with the digit 9. For example 139 is a rhino number because:

1. it is a prime
2. it ends in 9
3. The next prime number after it is 149 which also ends in 9. Note that 140, 141,
142, 143, 144, 145, 146, 147 and 148 are not prime so 149 is the next prime
number after 139.

Write a method named isRhinoNumber which takes an integer argument n and


returns 1 if it is a rhino number otherwise it return 0. So isRhinoNumber(139) would
return 1.

The function signature is


int isRhinoNumber(int n)

Some examples of numbers that are not rhino numbers are


Number Reason why it is not a rhino number
6 It is not a prime
17 Although it is prime, its last digit is not 9
It is prime and the last digit is 9 but the next prime number is 23
19
which does not end with 9
199 The next prime number, 211, does not end with 9

You may assume that a function named isPrime exists that returns 1 if its argument is
a prime, otherwise it returns 0. In other words, you do not have to write this function,
you just have to call it

Hint: Use modulo arithmetic to get the last digit of a number.

Potrebbero piacerti anche