pls answer quick for below question and explanation
An array is defined to be n-zero-packed if it contains two or more
non-zero elements and exactly n zeroes separate all non-zero elements
that would be adjacent if the zeroes were removed. For example, the
array {1, 0, 0, 18, 0, 0, -8, 0, 0} is 2-zero-packed because there are
two zeroes between the 1 and the 18 and two zeroes between the 18 and
the -8 and this accounts for all the non-zero elements. The array {0,
1, 0, 0, 0, 6, 0, 8, 0, 0, 4} is not 2-zero-packed because there are
three zeroes between the 1 and the 6 and only one zero between the 6
and the 8.
Write a function named isNZeroPacked with the following signature
If you are programming in Java or C#, the function signature is
int isNZeroPacked(int[ ] a, int n)
If you are programming in C++ or C, the function signature is
int isNZeroPacked(int a[ ], int len, int n) where len is the length of
the array.
The function returns 1 if its array argument is n-zero-packed (note
that n is passed as one of the arguments of the function)
Examples
a is and n is then function returns reason
{0, 0, 0, 2, 0, 2, 0, 2, 0, 0} 1 1 because exactly 1 zero separates
all the non-zero elements of the array
{0, 0, 0, 2, 3, 0, 2, 0, 0} 1 0 because values 2 and 3 are
separated
by no zeroes. In general there should not be consecutive non-zero
elements unless n is zero (see next example)
{1, 2, 3, 4} 0 1 because all non-zero elements are separated by
no zeroes
{12, 0, 0, 0, 0, 0, 0, 0, -8} 7 1 because exactly 7 zeroes
separate
all the non-zero elements of the array
{0, 0, 0, 0, 5, 0, 0, 4, 0, 0, 6} 2 1 because exactly 2 zeroes
separate all the non-zero elements of the array
{0, 0, 0, 0, 5, 0, 0, 4, 0, 0, 0, 6} 2 0 because there are three
zeroes between the 4 and the 6.
{0, 0, 0, 0, 5, 0, 4, 0, 0, 6} 2 0 because there is only one zero
between the 5 and the 4.
{0, 0, 0, 0} 3 0 because array must have at least two non-zero
elements
{0, 0, 1, 0, 0} 2 0 because array must have at least two non-zero
elements
Note: zeroes at the beginning and end of the array should be ignored.
On 8/5/13, sadi hassan <[email protected]> wrote:
> Hi Ali,
>
> Your answer is really good and inspiring.
>
> Which University you are currently enrolled in?
> Can you explain a bit about the admission process and research groups?
> I am trying to get into grad admission in a reputable university, but I am
> just getting failed to manage professors :-(
>
> However, thanks for a nice reply.
>
> Sadi
>
>
>
> On Mon, Aug 5, 2013 at 1:57 AM, Ali Abbasinasab
> <[email protected]>wrote:
>
>> Hi,
>>
>> Of course. Many students who used to participate (or still participating)
>> in programming contests (e.g. GCJ, TopCoder or ACM ICPC) are now grad
>> student in Computer Science or Computer Engineering (or maybe completed
>> their degree). Their research usually requires knowledge and skills in
>> algorithm design and programming to solve a practical problem. I'm
>> personally working on the reliability of memories with an emphasis of
>> curing electromigration which may sound completely off the topic.
>> However, what I am doing is developing algorithms and designing
>> combinatorial optimization techniques with the application of VLSI
>> circuits. My research requires a ton of algorithmic programming skills
>> that
>> I gained by involving in these contests. Obviously, sometimes I need to
>> know some other related materials in physics and electrical circuits in
>> order to have a good image of the problem and solve it correctly. There
>> are
>> also several fields which are purely related to the algorithm design and
>> its theoretical aspects that you can find in computer science programs.
>> Note that as a grad student you usually need to obtain some other skills
>> and dig in other theoretical materials in order to solve a real world
>> problem. All in all, although I'm solving a problem in the semiconductor
>> industry, it's nothing but designing algorithms and programming.
>>
>> Good luck.
>>
>>
>>
>>
>> On Sun, Aug 4, 2013 at 9:46 AM, Rick Goldstein
>> <[email protected]>wrote:
>>
>>> Hi,
>>>
>>> I was wondering if anyone has completed (or currently working towards) a
>>> CS/algorithm phd where the research problems and/or coursework are a
>>> similar flavor to the programming questions asked in the Google Code
>>> Jam?
>>>
>>> Thanks!
>>> Rick
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups
>>> "Google Code Jam" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an
>>> email to [email protected].
>>> To post to this group, send email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/google-code/2f8501ab-033d-4806-bddd-f4cbbdf4d3ab%40googlegroups.com
>>> .
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google Code Jam" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/google-code/CAMUfUqMwqab3fN9ZNRtKc41jVvAVV37qHLXi9O6-P7vui-wHkw%40mail.gmail.com
>> .
>>
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/CADv9SgFJjJeWqPRjkuNXRWkykt2wdQx%3DFm6b1%2BbFU5uqttrfwg%40mail.gmail.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/CAEvz5EmNq1GDhKgerf%3DON70F45TTrhqVpP7-5JhooU0Uu%2BBwpw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.