Skip to content

Conversation

aadil42
Copy link
Contributor

@aadil42 aadil42 commented Jun 9, 2023

Added a solution for repeated-dna-sequences in JS.

File(s) Added: 0187-repeated-dna-sequences.js
Language(s) Used: JavaScript
Submission URL: https://leetcode.com/problems/repeated-dna-sequences/submissions/984603175/

Added a solution for repeated-dna-sequences in JS.
};

function getSubSequance(s,i,len) {
return s.slice(i, i + len);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: This will change your time complexity. Refactor or review your Time O()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the len parameter is a constent(10 in this case). so the the time complexity would be 10*n which is still n right? Aren't we suppose to ignore the coefficient? But I have changed the time coplexity in the comment nonetheless.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! Since it is a constant, we can ignore the auxiliary space.

Updated Time complexity.

var findRepeatedDnaSequences = function(s) {

const sequanceStack = new Set();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable names are misleading

const sequenceSet = new Set();
const resultSet = new Set();

return [ ...resultSet ];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, my bad. Sorry. I updated the variables.

Updated variable names.
@aakhtar3
Copy link
Collaborator

aakhtar3 commented Jul 2, 2023

Fix conflict

@aadil42
Copy link
Contributor Author

aadil42 commented Jul 2, 2023

Hey @aakhtar3 there seems to be added code to mine. I didn't write it. Do you want me to keep this code in the file?

var findRepeatedDnaSequences = function (s) {
const seen = new Set();
const res = new Set();
const arr = Array.from(s);

for (let l = 0; l < arr.length - 9; l++) {
    const sequence = s.slice(l, l + 10);

    if (seen.has(sequence)) {
        res.add(sequence);
    } else {
        seen.add(sequence);
    }
}

return Array.from(res);

};

@aadil42
Copy link
Contributor Author

aadil42 commented Jul 3, 2023

Hey @aakhtar3, this is just a kind reminder. Let me know what should I do with the additional added code.

@aakhtar3
Copy link
Collaborator

You can add both solutions

@aadil42
Copy link
Contributor Author

aadil42 commented Jul 16, 2023

Oh, ok I'll do that.

@aadil42
Copy link
Contributor Author

aadil42 commented Jul 20, 2023

The conflict is resolved.

@aakhtar3 aakhtar3 merged commit 60bb25e into neetcode-gh:main Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants