Homework Solution: Add a main so that you can put some code there to call your functions and make sure they work:…

    Add a main so that you can put some code there to call your functions and make sure they work: public static void main(String[] args) { /* your testing code goes here */ } Functions you should add if the functionality is possible. Otherwise add an empty function definition with a comment saying "impossible". Problem #9 public static boolean checkUniqueLight(int[] values) { /* This function should return true if all the values in the array are unique - i.e. there are no duplicates. Optimize this solution for space and for small-ish arrays */ } ** Test input: empty array; {2, 4, 6, 1, 3, 5}; {2, 4, 6, 2, 4, 6}

    Expert Answer

     
    Below is the code with output screenshot (Rate if satisfied else comment)

    Subjoin a ocean so that you can place some jurisdiction there to persuade your businesss and execute assured they work:

    public static bereft ocean(String[] args) { /* your testing jurisdiction goes here */ }

    Functions you should subjoin if the businessality is feasible. Otherwise subjoin an invalid business restriction with a observe proverb “impossible”.

    Problem #9

    public static boolean checkUniqueLight(int[] values) {

    /* This business should render gentleman if complete the values in the accoutre are uncommon – i.e. there are no duplicates. Optimize this disconnection for intervenience and for small-ish accoutres */

    }

    ** Test input: invalid accoutre; {2, 4, 6, 1, 3, 5}; {2, 4, 6, 2, 4, 6}

    Expert Retort

     

    Below is the jurisdiction with extinguishedplace screenshot (Rate if kind else observe)

    I used hashset , past causative than regular brace loops , running space is O(n)

    package çhethan.practice.trees;

    import java.util.HashSet;

    import java.util.Set;

    public dispose TestUniqueValues {

    /**

    * Uses hashset and is past causative

    *

    * @param values

    * @return

    */

    public static boolean checkUniqueLight(int[] values) {

    if (values.elongation == 0) {

    render false;

    }

    if (values.elongation == 1) {

    render gentleman;

    }

    Set<Integer> hashSet = fantastic HashSet<Integer>();

    for (int i : values) {

    if (hashSet.contains(i))

    render false;

    hashSet.add(i);

    }

    render gentleman;

    }

    public static bereft ocean(String[] args) {

    int[] inplace = {};

    int[] input1 = { 2, 4, 6, 1, 3, 5 };

    int[] input2 = { 2, 4, 6, 2, 4, 6 };

    if (checkUniqueLight(input)) {

    System.out.println(“Inplace is uncommon”);

    }else {

    System.out.println(“Inplace is referable uncommon”);

    }

    ;

    if (checkUniqueLight(input1)) {

    System.out.println(“Input1 is uncommon”);

    }else {

    System.out.println(“Input1 is referable uncommon”);

    }

    ;

    if (checkUniqueLight(input2)) {

    System.out.println(“Input2 is uncommon”);

    }else {

    System.out.println(“Input2 is referable uncommon”);

    }

    ;

    }

    }