๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
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
If we get 5.5k subscribers today I'll share all answers with you .
No need to pay anyone โœŒ๏ธ
/*
167. Two Sum II - Input Array Is Sorted
Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length.
Return the indices of the two numbers, index1 and index2, added by one as an integer array [index1, index2] of length 2.
The tests are generated such that there is exactly one solution. You may not use the same element twice.
Your solution must use only constant extra space.
Example 1:
Input: numbers = [2,7,11,15], target = 9
Output: [1,2]
Explanation: The sum of 2 and 7 is 9. Therefore, index1 = 1, index2 = 2. We return [1, 2].
*/
class Solution
{
public:
vector<int> twoSum(vector<int> &nums, int target)
{
int i = 0, j = nums.size() - 1;
while (i < j)
{
int sum = nums[i] + nums[j];
if (sum == target)
return {i + 1, j + 1};
else if (sum > target)
j--;
else
i++;
}
return {}; // Target not found
}
};
// Time Complexity : O(N)
// Space Complexity : O(1)



Guys this is very very important questions for Amazon interview ๐Ÿ”ฅ
๐Ÿ‘2
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 โœ