Technical Interview with a Software Engineer - Algorithms & Data Structures

preview_player
Показать описание


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

#coding #programming #softwareengineering
Рекомендации по теме
Комментарии
Автор

I HOPE I GET CALLED BACK FOR THE ONSITE KINDA NERVOUS

KevinNaughtonJr
Автор

Please Like the video (it helps my channel a lot) and also

NickWhite
Автор

this is such an easy coding problem in Python. from collections import Counter Counter(string).most_common() -> [("a", 3), ("b", 2), ("c", 1)] -> for k, v in newstring += k*v -> return newstring

ahsin.shabbir
Автор

The content you two put out literally changed my life ❤ I'm glad people like you exist.

xzero
Автор

I've watched both of you while I was preparing for my interviews. Will do again probably when I get back to coding leetcode.

spectrum
Автор

Nope, run time is not n log n where n is the number of unique characters.

The complexity is O(n + m log m) where n js the length of string and m is the number if unique chars.

tusherity
Автор

Both of you are awesome

Our inspiration

Thanks Nick thanks Kevin

avisheksinha
Автор

use a LinkedHashMap and you get the "cccaaa" output.


So I used Java's streams to do this in a one liner and my timing out show it to execute faster (not sure how this will format):
input.chars()
.parallel()
.mapToObj(i -> (char) i)
.collect(Collectors.groupingBy(Function.identity(), LinkedHashMap::new, Collectors.counting()))
.entrySet()
.stream()
.parallel()
.sorted(Comparator.comparing(Entry::getValue, (s1, s2) -> {
return s2.compareTo(s1);
}))
.map(e -> IntStream.range(0, e.getValue().intValue())
.mapToObj(i -> e.getKey().toString())


drmangrum
Автор

Should time complexity is O(n + klogk) & memory is O(k) k is number of characters from a-Z?

taloto
Автор

I wonder if you could have not bothered with the heap and just sorted the array using the the same comparator and a built-in sort function.

Yarrler
Автор

two of the best programmers on YouTube in one place! Cool

treyquattro
Автор

Do you guys mind explaining why the runtime is O(nlogn)? To build the map, it'd be O(n). Then to add elements to the heap, it'd be O(logn). To remove would be O(logn). Therefore, the total runtime would be O(n + 2logn) which would be O(n)? Sorry, I'm a newbie.

StockDC
Автор

I created a map with counts and then split input string to array and finally quicksort string array using map counts.

Benpeterscode
Автор

My two favourite youtubers for algorithms in one video! fire.

justinlo
Автор

enjoyed so much..now going for nick's interview

md.akib
Автор

Cool lesson Thank you so much both of you !

ghcrocket
Автор

It was such a fun and instructive at the same time... Keep it up yo! We want more of this...

anikkhan
Автор

The size of the heap is upper bounded by the number of characters in your character set, which is constant. Wouldn't this mean that the time complexity is actually O(N) ?

loogtoob
Автор

And then there is me doing this in one line with the power of c# and linq:


public static string FrequencySort(string word) => new string(word.GroupBy(c => c).OrderByDescending(c => c.Count()).ThenBy(c => c.Key).SelectMany(c => c).ToArray());

MikyShooter
Автор

Great collaboration ! Thanks for such a good content !

manojrajasekar