package org.shkim.codility.test;

import java.util.Arrays;
import java.util.HashSet;

public class Test
{

	private static int solution(int A[])
	{

		int N = A.length;

		if (N ==0)
		{
			return 0;
		}
		
		Arrays.sort(A);

		HashSet<Integer> set = new HashSet<>();
		for (int i = 0; i < N; i++)
		{
			set.add(A[i]);
		}

		int checker = 0;
		int cnt = 0;

		for (int i = 0; i < N; i++)
		{
			checker = A[i];
			if (set.contains(checker))
			{
				set.remove(checker);
				cnt++;
			}
		}

		return cnt + 1;
	}

	public static void main(String[] args)
	{

		int A[] = { 7, 3, 7, 3, 1, 3, 4, 1 };
		System.out.println(solution(A));
	}
}

@@ -31,33 +31,8 @@
 t;%0A%0A
-import java.util.Arrays;%0A
 impo
@@ -142,64 +142,8 @@
 h;%0A%0A
-%09%09if (N ==0)%0A%09%09%7B%0A%09%09%09return 0;%0A%09%09%7D%0A%09%09%0A%09%09Arrays.sort(A);%0A%0A
 %09%09Ha
@@ -243,104 +243,197 @@
 %0A%0A%09%09
-int checker = 0;%0A%09%09int cnt = 0;%0A%0A%09%09for (int i = 0; i %3C N; i++)%0A%09%09%7B%0A%09%09%09checker = A%5Bi%5D;%0A
+HashSet%3CInteger%3E copy;%0A%0A%09%09int temp = Integer.MAX_VALUE;%0A%0A%09%09for (int i = 0; i %3C N; i++)%0A%09%09%7B%0A%09%09%09copy = new HashSet%3C%3E();%0A%0A%09%09%09copy.addAll(set);%0A%0A%09%09%09for (int j = i; j %3C N; j++)%0A%09%09%09%7B%0A%09
 %09%09%09if (
-set
+copy
 .con
@@ -442,18 +442,16 @@
 ins(
-checker
+A%5Bj%5D
 ))%0A
+%09
 %09%09%09%7B
@@ -459,19 +459,21 @@
 %09%09%09%09
-set
+%09copy
 .remove(
 chec
@@ -472,28 +472,134 @@
 ove(
-checker);%0A%09%09%09%09cnt++;
+A%5Bj%5D);%0A%09%09%09%09%7D%0A%0A%09%09%09%09if (copy.isEmpty())%0A%09%09%09%09%7B%0A%09%09%09%09%09if (j - i + 1 %3C temp)%0A%09%09%09%09%09%7B%0A%09%09%09%09%09%09temp = j - i + 1;%0A%09%09%09%09%09%7D%0A%09%09%09%09%09break;%0A%09%09%09%09%7D
 %0A%09%09%09
@@ -618,15 +618,12 @@
 urn 
-cnt + 1
+temp
 ;%0A%09%7D

change test