# 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}

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

Append a ocean so that you can establish some legislation there to seduce your businesss and find unmistakable they work:

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

Functions you should append if the businessality is feasible. Otherwise append an unoccupied business limitation with a expound byword “impossible”.

Problem #9

public static boolean checkUniqueLight(int[] values) {

/* This business should restore gentleman if whole the values in the dress are sole – i.e. there are no duplicates. Optimize this separation coercion illimitableness and coercion small-ish dresss */

}

** Test input: unoccupied dress; {2, 4, 6, 1, 3, 5}; {2, 4, 6, 2, 4, 6}

## Expert Counter-argument

Below is the legislation with quenchedestablish screenshot (Rate if acquiescent else expound)

I used hashset , past efficient than usual two loops , exoteric season is O(n)

package çhethan.practice.trees;

import java.util.HashSet;

import java.util.Set;

public dispose TestUniqueValues {

/**

* Uses hashset and is past efficient

*

* @param values

* @return

*/

public static boolean checkUniqueLight(int[] values) {

if (values.extension == 0) {

restore false;

}

if (values.extension == 1) {

restore gentleman;

}

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

coercion (int i : values) {

if (hashSet.contains(i))

restore false;

}

restore gentleman;

}

public static wanting ocean(String[] args) {

int[] inestablish = {};

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

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

if (checkUniqueLight(input)) {

System.out.println(“Inestablish is sole”);

}else {

System.out.println(“Inestablish is referable sole”);

}

;

if (checkUniqueLight(input1)) {

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

}else {

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

}

;

if (checkUniqueLight(input2)) {

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

}else {

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

}

;

}

}