If we get 5.5k subscribers today I'll share all answers with you .
No need to pay anyone โ๏ธ
No need to pay anyone โ๏ธ
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
/*
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 ๐ฅ
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
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
Publicis Sapient
Role: Data Analytics Intern Batch Eligible: Only 2022 Graduation
https://docs.google.com/forms/d/e/1FAIpQLSeCSZluPV_q2C9lpJ42mBOVVsm57T4VVr_JqlAHs9XJKA3LDA/viewform
Role: Data Analytics Intern Batch Eligible: Only 2022 Graduation
https://docs.google.com/forms/d/e/1FAIpQLSeCSZluPV_q2C9lpJ42mBOVVsm57T4VVr_JqlAHs9XJKA3LDA/viewform
RoutePairs
C++ languageโ (Amazon)
C++ languageโ (Amazon)
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
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
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
Forwarded from OffCampus Jobs | OnCampus Jobs | Daily Jobs Updates | Lastest Jobs | All Jobs | CSE Jobs | Fresher Jobs โฅ (Dushyant)
'''
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 โ
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 โ
Revature (Python 3)โ
Revature (Python 3)โ
First line chnage
n=int(input())
Revature (Python 3)โ
n=int(input())
Revature (Python 3)โ