Question: Compute the distance between element positions. 6 0 4 2 8 0 . 3 7 3 5 6 5 8 . qx 3 zqy 7
Compute the distance between element positions.
qxzqy
Compute the distance between the positions of the first and last zero element in the given array. For example, if the array is
your algorithm should yield
If the array contains a single zero, return If it doesn't contain any zeroes, return a negative value.
Numbers.java
NumbersTester.javapublic class Numbers
public static int zeroesDistancedouble values
int firstPos ;
int lastPos values.length ;
boolean found false;
while firstPos values.length && found
Your code goes here
return lastPos firstPos;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
