Have you heard of YANDEX? | Fixed Size Sliding Window Problem - Permutation in String - Leetcode 567

preview_player
Показать описание
dynamic programming, leetcode, coding interview question, data structures, data structures and algorithms, faang
Рекомендации по теме
Комментарии
Автор

Master Data Structures & Algorithms For FREE at AlgoMap.io!

GregHogg
Автор

Yandex have a pretty good reverse image search

sanjeevsinghrajput
Автор

It is a russian company. Basically, russian Google

timuchin
Автор

Only difference I had was using a map instead of just a basic array for the frequency graphs. If I had to guess, the array is probably better in both compute time and memory compared to a map with it's overhead, but it only works assuming the strings only contain the 26 English lowercase alphabet characters. Here would be my Java submission:

private static final BiFunction<Integer, Integer, Integer> ADD = (a, b) -> {
int s = a + b;
return s == 0 ? null : s;
};

private static boolean perm(String s1, String s2) {
HashMap<Character, Integer> f1 = new HashMap<>(), f2 = new HashMap<>();
for (char c : s1.toCharArray()) {
f1.merge(c, 1, ADD);
}
char[] s2a = s2.toCharArray();
int l1 = s1.length(), l2 = s2a.length, n = l1;
for (byte i = 0; i < l1; ++i) {
f2.merge(s2a[i], 1, ADD);
}
do {
if (f1.equals(f2)) {
return true;
}
f2.merge(s2a[n - l1], -1, ADD);
f2.merge(s2a[n], 1, ADD);
} while (++n < l2);
return false;
}

dial-upking
Автор

love your content it's fantastic and full of valuable lessons

MichaelOnayan
Автор

Isn’t "d", "c" and "" also permutations of "dc"?

SKOBRY
Автор

and nobody said it cannot contain capital letters, numbers, chars in that string not forgetting some countriers wierd characters basically unicode ...

Daimakaicho
Автор

how efficient is it to use list instead of hashmap in this case? ive heard that using map is better when it comes to alphabets but I dont get why

dohunkim
Автор

"...well neither have I" xD!

ivanmorales
Автор

lol have you heard of Yandex? ?? That’s gold.

I’ll say that no one should know them

michaelmatveev
Автор

Can't u just do something like this:

1. If s1 is longer then s2 return false
2. For each char x in s1
-> if s2 contains x
-> -> remove x from s2
-> else return false
Return true

micah