On 8/5/13, bala subramanian <[email protected]> wrote: > 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.
-- 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/CAEvz5En47KCZrSCYDbL6G3woFbp3rpDY3O4A1tkR%3D%2BD_xz1s6A%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
