๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.63K subscribers
5.61K photos
3 videos
95 files
10.6K links
๐ŸšฉMain Group - @SuperExams
๐Ÿ“Job Updates - @FresherEarth

๐Ÿ”ฐAuthentic Coding Solutions(with Outputs)
โš ๏ธDaily Job Updates
โš ๏ธHackathon Updates & Solutions

Buy ads: https://telega.io/c/cs_algo
Download Telegram
Approach: we need to calculate the forward route list + return route list 2nd point and we will find the maximum of the list after that I will compare the forward route list and +return list if they are equal then I will push in 1 D vector then I will push 2nd vector in answer and finally we will return 2D vector answer


Complexity Analysis:
time complexity O(N*M)
N is the size of the forward route list and return route list
space complexity O(N*M)
and here N and M is the size of our 2D vector answer
๐Ÿ‘1
'''
Find K Closest Points to the Origin

Approach: The idea is to calculate the Euclidean distance from the origin for every given point and sort the array according to the Euclidean distance found. Print the first k closest points from the list.

Algorithm :
Consider two points with coordinates as (x1, y1) and (x2, y2) respectively. The Euclidean distance between these two points will be:

โˆš{(x2-x1)2 + (y2-y1)2}
Sort the points by distance using the Euclidean distance formula.
Select first K points form the list
Print the points obtained in any order.


Complexity Analysis:

Time Complexity: O(n log n).
Time complexity to find the distance from the origin for every point is O(n) and to sort the array is O(n log n)
Space Complexity: O(n).
As we are making an array to store distance from the origin for each point.

'''
def deliveryPlan(allLocation, NumDeliveries):

allLocation.sort(key = lambda NumDeliveries: NumDeliveries[0]2 + NumDeliveries[1]2)

return allLocation[:NumDeliveries]

Amazon โœ