Given an array of characters, find the longest continuous non-repeating sequence of characters

Ex: aabcdefdghiajk – efdghiajk

 

char[] str = {‘a’,’a’,’b’,’c’,’d’,’e’,’f’,’d’,’g’,’h’,’i’,’a’,’j’,’k’};
int len = str.length;
System.out.println(“len “+len);
Map m = new LinkedHashMap();

for (int i = 0; i < len; i++) {
System.out.println(str[i]+” “+i);
if(m.containsKey(str[i])){
System.out.println(“found”);
i = (int) m.get(str[i]);
System.out.println(“new i”+i);

m.clear();
}else{

m.put(str[i], i);
}

}

Advertisements