Only Premium Users can view the Question
Oncampus Round
CGPA Cutoff - 6
Branches Allowed - Circuital
Offer type - Sde Intern + ppo opportunity
Stipend - Rs 1,10,000
Round 2: The next round was a technical interview round . It went of for around 1 hour. The interview started with basic introduction and little bit about my projects. Then Interviewer started with the DSA questions and in total 2 questions were asked in nearly 45 minutes. Level - Medium
Question 1 : It was a question based on Binary Search and two pointers.The question was - https://www.geeksforgeeks.org/find-k-closest-elements-given-value/ I started with the first approach by using minHeap and then interviewer asked me to optimize the solution and then came up with the binary search and two pointers approach. And then he asked me to code the same and dry run it.
Question 2 : It was a variation of two sum problem of medium level . The interviewer got satisfied with my approach and dry run and I asked should I code it but he said he was satisfied with my solution and didn't need to code.
The question I asked at the end of interview in Q&A was:-In which team they were working and how is their experience regard to work-life balance And how is 6-month internship different from 2 months
Tips And Unique Points from Interview.
Overview
Approach
Better Approach
Complexity
PseudoCode
while(l < r){
sum=array[l]+array[r];
if(sum < k){
l++;
}
else if(sum > k){
r--;
}
else{
cout << array[l]<<" "<
Approach 1
Approach 2 (Space optimized)
Complexity
sort the array.
we will look for k+1 closet element.
Predicate : X - arr[i] <= arr[i+(k+1)] - X
Predicate will reduce our problem to F* T* pattern and we are interested in finding the position (index) offirst True(T).
TC is O(nlogn) due to sorting
SC isO(1).
lo = 0, hi = n-k-1;
while(lo<hi){
mid = lo+(hi-lo)/2;
if(x-arr[mid] <= arr[mid+k+1]-x){
hi = mid;
} else {
lo = mid+1;
}
}
for(int i = lo ; i<lo+k+1 ;i++){
if(arr[i]!=x) {
cout<<arr[i]<<" ";
}
}
def find_pair(n, k, arr):
arr.sort()
left, right = 0, n - 1
while left < right:
current_sum = arr[left] + arr[right]
if current_sum == k:
return [arr[left], arr[right]]
elif current_sum < k:
left += 1
else:
right -= 1
n, k = map(int, input().split())
arr = list(map(int, input().split()))
result = find_pair(n, k, arr)
print(*sorted(result))
Hello Harsh Priyadarshi, I was trying this problem(handle: code__raider), but it is giving WA at 2nd test case only. Way 1: If I store the array, failing at 2nd test because "6 12, 7 3 5 8 1" here no. of elements should be 6 instead on 5. Please check this once.
Way2: If I don't store the array and just go with the HashMap, it is getting failed at 11th test. Approach seems alright. Please check this as well
No. of elements was a typo. It is fixed. Testcase 11 is fixed as well.
thanks Harsh, it's accepted now!!!