Uber | SDE 2 | Bangalore | Sep 2024 [Reject]

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-10-04Added By Anonymous
Source: Link

Company: Uber

Role: SDE 2

Interview Stage: Phone Screen

Location: Bangalore

Year: 2024


Original Post Content:


Status: 4+ years of experience

Position: SDE 2 at Amazon

Location: Bangalore, India

Date: September 2024

---


OA: Code Signal | General Coding Framework | 70 mins | 4 Questions

Below is the summary for questions

1. Given an array, find sum such that if

If a[i] < a[i+1] then add 1

If a[i] > a[i+1] then add 2

2. Given String1 = panel and set of strings namely codes, for each index1 i in code in codes, check if the string to the right of index1 matches the string at index2 of panel formed by taking digits to the left of index1 in code (Implementation heavy string matching) (Took me the most time: 17 mins)

3. Rotten Oranges

4. Given an array of 0's and 1's only and below 2 operations as m queries, return resultant array after performing all operations

L: switch 0 at smallest index to 1 if any

C{index}: change value at index to 0


Scored 600/600. Verdict: Passed.

---


Business Phone Screen [Elimination Round]: Code Signal | 60 minutes | 1 Med + Hard Follow Up


Given a sorted array with positive and negative values, sort them based on the square of its values. Also, print the squared values array.

- Expected O(N) working code and interviewer made me run the code with sample tests and compare output

- Sample: [-7, -2, -1, -1, 1, 2, 2, 2, 3, 5] => [-1, -1, 1, -2, 2, 2, 2, 3, 5, -7]


Follow Up: Now, given the same array, how would you modify your code to find the kth smallest square element in the array. Expected O(LogN)


The problem can be reduced to finding the kth smallest element in union of two sorted arrays similar to median of two sorted arrays

Was not able to provide an O(LogN) working solution for the 2nd question. Interviewer gave no hints.


Verdict: Rejected. Received same day outcome

---


Solution to Follow Up Question:


#include<bits/stdc++.h>

using namespace std;


#define LL long long

#define MOD 1000000007

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define print(a, n) for(auto _=0; _<n; _++) cout<<a[_]<<" "; cout<<"\n"

#define prints(a) for(auto _: a) cout<<_<<" "; cout<<"\n"

#define read(a, n) for(auto _=0; _<n; _++) cin>>a[_]


// Y = -7 -2 -1 -1

// X = 1 2 2 2 3 5


// Squared sorted X + Y: 1 1 1 4 4 4 4 9 25 49


int binarySearch(int pivot, int k, int n, vector<int>& nums) {

int low = pivot-1, high = n;


// Ex: K = 8;

while (low <= high) {

int partitionX = (low + high)/2; // (4+10)/2 = 7 | (7+10)/2 = 8

if (partitionX + 1 < k) {

low = partitionX;

continue;

}


int partitionY = (partitionX+1 - k); // (7+1 - 8) = 0 | (8+1 - 8) = 1


int LeftX = partitionX >= pivot ? nums[partitionX] : INT_MIN; // 2 | 3

int RightX = partitionX+1 < n ? nums[partitionX+1] : INT_MAX; // 3 | 5


int LeftY = partitionY > 0 ? -nums[partitionY-1] : INT_MAX; // INT_MAX | 7

int RightY = partitionY < pivot ? -nums[partitionY] : INT_MIN; // 7 | 2


if (LeftX <= LeftY && RightY <= RightX) // 2 < INT_MAX && 7 < 3 => false | 3 < 7 && 2 < 5 => true

return max(LeftX*LeftX, RightY*RightY); // max(3*3, 2*2) => 9


if (LeftX > LeftY) // 2 > INT_MAX => false

high = partitionX;

else

low = partitionX; // low = 7

}


return -1;

}


int lb(int target, vector<int>& nums) {

int low = 0, high = nums.size();

while (low < high) {

int mid = low + (high - low)/2;

if (nums[mid] < target)

low = mid + 1;

else

high = mid;

}


return low;

}


int solve(vector<int> nums, int k) {

int n = nums.size();

int pivot = lb(0, nums);


if (pivot == n) // all negative numbers

return nums[n-k]*nums[n-k];

else if (pivot == 0) // all positive numbers

return nums[k-1]*nums[k-1];

else

return binarySearch(pivot, k, n, nums);

}


int main()

{

fastio;

cout<<solve({-7, -2, -1, -1, 1, 2, 2, 2, 3, 5}, 1)<<endl;

cout<<solve({-7, -2, -1, -1, 1, 2, 2, 2, 3, 5}, 2)<<endl;

cout<<solve({-7, -2, -1, -1, 1, 2, 2, 2, 3, 5}, 3)<<endl;

cout<<solve({-7, -2, -1, -1, 1, 2, 2, 2, 3, 5}, 4)<<endl;

cout<<solve({-7, -2, -1, -1, 1, 2, 2, 2, 3, 5}, 5)<<endl;

cout<<solve({-7, -2, -1, -1, 1, 2, 2, 2, 3, 5}, 6)<<endl;

cout<<solve({-7, -2, -1, -1, 1, 2, 2, 2, 3, 5}, 7)<<endl;

cout<<solve({-7, -2, -1, -1, 1, 2, 2, 2, 3, 5}, 8)<<endl;

cout<<solve({-7, -2, -1, -1, 1, 2, 2, 2, 3, 5}, 9)<<endl;

cout<<solve({-7, -2, -1, -1, 1, 2, 2, 2, 3, 5}, 10)<<endl;


cout<<solve({-7, -2, -1, -1, 2, 2, 2, 2, 3, 5}, 1)<<endl;

cout<<solve({-7, -2, -1, -1, 2, 2, 2, 2, 3, 5}, 2)<<endl;


cout<<solve({-5, -4, -3, -2, 10, 20, 30}, 2)<<endl;

cout<<solve({-5, -4, -3, -2, 10, 20, 30}, 3)<<endl;

cout<<solve({-5, -4, -3, -2, 10, 20, 30}, 6)<<endl;


cout<<solve({-7, -2, -1, -1}, 2)<<endl;

cout<<solve({-7, -2, -1, -1}, 3)<<endl;


cout<<solve({1, 2, 2, 2, 3, 5}, 2)<<endl;

cout<<solve({1, 2, 2, 2, 3, 5}, 4)<<endl;

cout<<solve({1, 2, 2, 2, 3, 5}, 6)<<endl;

exit(0);

}

Comments