Question: Given an array containing only 0 and 1 values. for example: 1 0 1 1 1 0 1 1 1 1 1 1 0 Write
Given an array containing only 0 and 1 values. for example: 1 0 1 1 1 0 1 1 1 1 1 1 0 Write a class called TestQ1 and inside it write a static method whose signature - public static void distance(int[] a) The method will accept as an array parameter as described above. The method will replace each cell whose value is 1 at the distance of this cell from the nearest zero (to its right or left). For example, for the array above, after running the method the array will look like this - 1 0 1 2 1 0 1 2 3 3 2 1 0 The distance between a cell containing a 1 and a cell containing a zero is simply the number of steps it takes to get from one to the other. The method should be as efficient as possible, both in terms of time complexity and in terms of memory. A method that is not effective enough will not receive full points. Write down the time complications of the method you wrote in the Answers file. B. (5 points) Write a main method in the class, and within it run the method on some array of length at least 10 and print the result of the method.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
