NeetCode 1 word solutions Flashcards

1
Q

W: Find Duplicate Elements in Array

A

Duplicates cannot be added in Hashmap.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Find if two strings are anagram of each other

A

2 Hashmaps.

Add character as key and count as value.

Compare 2 Hashmaps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

TWO SUM in an array

A

1 Hashmap.

Calculate difference = Target - n.

If Difference present in Map return. Else add it to hashmap.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

GROUP ANAGRAMS

A

o(m*n)

hashmap(list)

key = [list of same char/value count]

value = [list of strings]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

TOP K Frequent Elements

A

O(m+n)
Reverse bucket sort.

First count the nums using hashmap.

Array - index is count , value is array of numbers with that (index) count.

Read array from last index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Encode and Decode String

A

1) Add number of characters followed by # before every string

2) Seperate each string with ; , If it already has ; , add \ esacpe character before every special character. to tell that consider the next character after \ as a part of string

3) JSON Serialisation 4) Hexadecimal;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Product of Array except self without /

A

1) Using / is easy with O(n)

2) Prefix array * Postfix array - takes up space.

3) Single output array. Prefix variable and post fix variable.

Key is to fill the prefix/postfix variable value in the array position.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Longest Sequence in An Array

A

Use the SET.
FInd if the value has previous element. If no then it is start of a sequence. Then find the next elements present or not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly