Belated guru purnima Navdeep ! You're one of the best teachers I've ever had. Thank you for picking up this profession.
@aashishbathe3 ай бұрын
A 1 liner solution for python peeps - return [name for height, name in sorted(zip(heights, names), reverse=True)] Selection sort code - curr = 0 curr_height = heights[0] while curr < len(names) - 1: tmp, tmp_height = curr, heights[curr] for i in range(curr + 1, len(names)): if heights[i] > tmp_height: tmp = i tmp_height = heights[i] heights[tmp], heights[curr] = heights[curr], heights[tmp] names[tmp], names[curr] = names[curr], names[tmp] curr += 1 return names
@marcosfvarani3 ай бұрын
Today the problem actually shows an example with non-distinct names! I think the best approach now is to use a tuple of name and heights rather than a map
@DeathSugar3 ай бұрын
the most efficient so far was to make tuples and sort it by height in tuple.
@rameezalipacific3 ай бұрын
I'm from Pakistan and currently pursuing a degree in software engineering. Alongside my studies, I'm dedicating significant time to mastering data structures and algorithms (DSA). However, I'm uncertain if excelling in DSA alone is enough to secure a job at top tech companies like the one you work for. Do I need to develop additional skills, such as web, app, or game development, to increase my chances of success? Also, could you share your experience on when you started focusing on DSA-was it during your degree or afterward?
@TheGoat18393 ай бұрын
class Solution: def sortPeople(self, names: List[str], heights: List[int]) -> List[str]: number_of_people = len(names) # Create a dictionary to store height-name pairs height_to_name_map = dict(zip(heights, names)) sorted_heights = sorted(heights, reverse=True) # Create a list of sorted names based on descending heights sorted_names = [height_to_name_map[height] for height in sorted_heights] return sorted_names is this a better solution , or your solution has less complexcity?
@rahulsbhatt3 ай бұрын
What do you think is faster? 1. heights.sort(reverse = True) 2. reversed(sorted(heights))
@NeetCodeIO3 ай бұрын
Probably first since it's in place, but I don't think the second actually reverses the array it just returns an iterator in reverse order
@minhtungbui20023 ай бұрын
Thank you so much for your solution. In this problem I used pair and lambda function to solve it and it's also very nice:v
@md_pedia13 ай бұрын
Can't v use a heap for this question?
@aashishbathe3 ай бұрын
@@md_pedia1 yeah we can, but then we need O(n) to combine the elements and heapify them. Also O(nlogn) for popping elements and getting result.
@md_pedia13 ай бұрын
@@aashishbathe it didnt occur to me at that time😅
@31redorange083 ай бұрын
What's v?
@rahulsbhatt3 ай бұрын
Wish there were comparators in python! None the less, you have written clean code!