Here is a problem given in my class:
boolean stringIntersect(String a, String b, int len)
Given 2 strings, consider all the substrings within them of length len. Returns true if there are any such substrings which appear in both strings. Compute this in O(n) time using a HashSet. Len will be 1 or more.
T Collections int sameCount(Collection T a, Collection T b)
In the Appearances class, the static Appearances.sameCount() method takes in two collections -- A and B -- containing a generic element type. Assume that the T elements implement equals() and hashCode() correctly, and so may be compared and hashed. The elements are in no particular order. Every element in A appears in A one or more times, using .equals() to compare elements for equality (the standard definition of equals() for java collections). Likewise every element in B appears one or more times. sameCount() counts the number of elements that appear in both collections the same number of times.
For example, with the collections {"a", "b", "a", "b", "c"} and {"c", "a", "a", "d", "b", "b", "b"} it returns 2, since the "a" and the "c" appear the same number of times in both collections. Use hashing to compute the number of appearances efficiently.
I have couple of questions about this.
in the boolean stringIntersect(String a, String b, int len) how can I load a string in a hashset? Should i insert each letter to a hashset? if so then what about the duplicate letters? I can compare elements and do the tasks of T Collections int sameCount(Collection T a, Collection T b) I guess.
There's is a parameter "len" in "boolean stringIntersect(String a, String b, int len)". But in the example the two strings are of different length. So what will be "len"?