Part I of this question says:Fill in the smoosh() method in the Homework3 class so that it performs as indicated in the comment. Your solution should not use linked lists, nor should it use your squish() method.Here is the below code written for smoosh(), in more than 14 lines. Modular testing is done for this method smoosh().public class Homework3 {  /**   *  smoosh() takes an array of ints.  On completion the array contains   *  the same numbers, but wherever the array had two or more consecutive   *  duplicate numbers, they are replaced by one copy of the number.  Hence,   *  after smoosh() is done, no two consecutive numbers in the array are the   *  same.   *   *  Any unused elements at the end of the array are set to -1.   *   *  For example, if the input array is [ 0 0 0 0 1 1 0 0 0 3 3 3 1 1 0 ],   *  it reads [ 0 1 0 3 1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 ] after smoosh()   *  completes.   *   *  @param ints the input array.   **/    public static void smoosh(int[] a) {     // Fill in your solution here.  (Ours is fourteen lines long, not counting     // blank lines or lines already present in this file.)       int currentPointer = 1;       int i, j = 0;       for(i =0; i < a.length; i++){          int flag = 0;          for(j = currentPointer; j < a.length; j++)             if(a[j] != a[i])             {                a[i+1] = a[j];                currentPointer = ++j;                flag = 1;                break;             }          if(j == a.length){             if(flag == 1)                i+=2;             else                i += 1;             for(int k = i; k < a.length; k++)                a[k] = -1;             break;          }      }  }  /**   *  stringInts() converts an array of ints to a String.   *  @return a String representation of the array.   **/  private static String stringInts(int[] ints) {    String s = [  ;    for (int i = 0; i < ints.length; i++) {      s = s + Integer.toString(ints[i]) +   ;    }    return s + ];  }  /**   *  main() runs test cases on your smoosh and squish methods.  Prints summary   *  information on basic operations and halts with an error (and a stack   *  trace) if any of the tests fail.   **/  public static void main(String[] args) {    String result;    int i;    System.out.println(Let's smoosh arrays!\n);    int[] test1 = {3, 7, 7, 7, 4, 5, 5, 2, 0, 8, 8, 8, 8, 5};    System.out.println(smooshing  + stringInts(test1) + :);    smoosh(test1);    result = stringInts(test1);    System.out.println(result);    TestHelper.verify(result.equals(            [  3  7  4  5  2  0  8  5  -1  -1  -1  -1  -1  -1  ]),                      BAD SMOOSH!!!  No cookie.);    int[] test2 = {6, 6, 6, 6, 6, 3, 6, 3, 6, 3, 3, 3, 3, 3, 3};    System.out.println(smooshing  + stringInts(test2) + :);    smoosh(test2);    result = stringInts(test2);    System.out.println(result);    TestHelper.verify(result.equals(            [  6  3  6  3  6  3  -1  -1  -1  -1  -1  -1  -1  -1  -1  ]),                      BAD SMOOSH!!!  No cookie.);    int[] test3 = {4, 4, 4, 4, 4};    System.out.println(smooshing  + stringInts(test3) + :);    smoosh(test3);    result = stringInts(test3);    System.out.println(result);    TestHelper.verify(result.equals([  4  -1  -1  -1  -1  ]),                      BAD SMOOSH!!!  No cookie.);    int[] test4 = {0, 1, 2, 3, 4, 5, 6};    System.out.println(smooshing  + stringInts(test4) + :);    smoosh(test4);    result = stringInts(test4);    System.out.println(result);    TestHelper.verify(result.equals([  0  1  2  3  4  5  6  ]),                      BAD SMOOSH!!!  No cookie.);   } /* end main*/}/* end Homework3 class */TestHelperpublic class TestHelper {  /**   *  verify() checks an invariant and prints an error message if it fails.   *  If invariant is true, this method does nothing.  If invariant is false,   *  the message is printed, followed by a dump of the program call stack.   *   *  @param invariant  the condition to be verified   *  @param message  the error message to be printed if the invariant fails to   *                  hold true.   **/  static void verify(boolean invariant, String message) {    if (!invariant) {      System.out.println(*** ERROR:   + message);      Thread.dumpStack();    }  }}Test case output:Let's smoosh arrays!smooshing [  3  7  7  7  4  5  5  2  0  8  8  8  8  5  ]:[  3  7  4  5  2  0  8  5  -1  -1  -1  -1  -1  -1  ]smooshing [  6  6  6  6  6  3  6  3  6  3  3  3  3  3  3  ]:[  6  3  6  3  6  3  -1  -1  -1  -1  -1  -1  -1  -1  -1  ]smooshing [  4  4  4  4  4  ]:[  4  -1  -1  -1  -1  ]smooshing [  0  1  2  3  4  5  6  ]:[  0  1  2  3  4  5  6  ]Can you please help me guide to squeeze smoosh() to 14 lines?Please provide comments on readability vs optimization for an existing solution of the smoosh() method.Note: This is online self learning course from UOC berkeley.
Optimizing smoosh() method further
java;array
Your code advances an index until it finds an element that is differentfrom the current element a[i] and copies that to a[i+1]. The fillingpart is bit involved because you have to distinguish whether an elementwas copied into a[i+1] or not (your flag).To work towards the given line limit, you use non-trivial for and ifstatements without braces { ... }, which does not increase thelegibility and is error-prone (if more statements are added tothe for/if-expression later).It becomes simpler if you think the other way around: Copy the currentelement from the original position to the target position first, thenadvance the original position until a different element is found.This will copy some elements unnecessarily to itself, but leads to the followingfunction (13 lines in total without the comments) which should be self-explaining:public static void smoosh(int[] a) {    int originalPos = 0;    int targetPos = 0;    while (originalPos < a.length) {        // Copy (and remember) one element to the correct position:        int currentElement = a[targetPos++] = a[originalPos++];        // Advance originalPos until a different element is found:        while (originalPos < a.length && a[originalPos] == currentElement) {            originalPos++;        }    }    // Fill remaining elements:    while (targetPos < a.length) {        a[targetPos++] = -1;    }}(Everything apart from the smoosh() function itself seems to be prescribedby the given homework skeleton, so I am not going to comment on that.)