hashmap to find longest sequence with duplicates