educative.io

Heads up: proposed solution solves another problem, the solution to the question should be the following

import java.util.*;
import java.util.stream.Collectors;

public class Test{
    public static List<String> findRepeatedSequences(String s, int k) {
        HashMap<String, Integer> cache = new HashMap<>();
        for (int end = 0, start = 0; end < s.length(); end++) {
            if (end - start + 1 >=k) {
                cache.put(s.substring(start, end+1), cache.getOrDefault(s.substring(start, end+1), 0) + 1);
                start++;
            }
        }

        return cache
                .entrySet()
                .stream()
                .filter(entry -> entry.getValue() > 1)
                .map(Map.Entry::getKey)
                .collect(Collectors.toCollection(LinkedList::new));

    }

    public static void main(String[] args) {
        assert findRepeatedSequences("AGCTGAAAGCTTAGCTG", 5).equals(List.of("AGCTG"));
        assert findRepeatedSequences("AGAGCTCCAGAGCTTG", 6).equals(List.of("AGAGCT"));
        assert findRepeatedSequences("ATATATATATATATAT", 6).equals(List.of("ATATAT", "TATATA"));
    }

}

Course: Grokking Coding Interview Patterns in Java - Learn Interactively
Lesson: Repeated DNA Sequences - Grokking Coding Interview Patterns in Java

Hello Davide,
The solution you proposed throws an error every time we run it, but from the look of it we can say that it’s time complexity is more than O(n). The best possible solution is where we have the least time complexity which is O(n).
Happy learning :slight_smile:

That is exactly the issue I was reporting.
Looking at the solution the return type of the method differs from the return type of the same method in the practicing area (the one where you have to write the code).


Course: https://www.educative.io/collection/5642554087309312/5724822843686912
Lesson: https://www.educative.io/collection/page/5642554087309312/5724822843686912/5760131769827328

Can you please follow up on this one?


Course: Grokking the Behavioral Interview - Learn Interactively
Lesson: https://www.educative.io/courses/grokking-the-behavioral-interview/x14gW3NDwoP

Hi Davide,

We’re really sorry for the delay. We’re looking into the issue and will try to get back to you with our findings as soon as possible.

Thanks for this and the other feedback that you have provided on this course!