Open In App

Rippling Interview Experience for SDE (FTE+6 Month Internship)

Selection Process: Online coding round:   the questions are 2 medium-hard and 1 easy-medium coding questions based on tree+dp, binary search. I was able to clear this round by solving 2.5 questions and the shortlisted candidates were called for interviews.

Round 1(45 min): Started with the interviewer’s Intro and then mine. Then he asked me about my project. Later a Question.



I have coded each of these approaches.

 Recursive approach:  






int maxSum(int current_index, int k, vector<int>& arr)
{
     if(current_index==n-1) return arr[n-1];
     int ans=INT_MIN;
     for(int i=current_index+1; i<min(n-1,current_index+k); i++)
       ans=max(ans, maxSum(i,k,arr)+arr[current_index]);
      return ans;
}
 
cout<<maxSum(0, k, arr);

DP approach:




int dp[n];
dp[n-1]=arr[n-1];
for(int i=n-2; i>=0; i++)
{
   dp[i]=INT_MIN;
   for(int j=i+1; j<=min(n-1,i+k); j++)
     dp[i]=max(dp[i], dp[j]+arr[i]);
    
}
cout<<dp[0]; //time complexity-O(n*k)

Priority_queue approach:




priority_queue<pair<int,int>> pq; //max heap -stores { dp[i], i}
pq.push({arr[n-1],n-1});
int last_element=arr[n-1];
for(int i=n-2; i>=0; i--)
{
    //we have to find max dp[j] value from range i+1 to i+k
    // first we pop max elements which are out of range
     while(!pq.empty() && pq.top().second>i+k) pq.pop();
     int g=pq.top().first+arr[i]; // heap will be not empty
      pq.push({g,i});
     last_element=g;
}
 cout<<last_element; //time complexity -O(nlongn) 

Deque approach:




int dp[n];
deque<int> dq;
dq.push(0);
dp[n-1]=arr[n-1];
/*  in deque , we will store indices but
 in the order of decending order of dp values
  
*/
for(int i=n-2; i>=0; i--)
{
    //remove front indices which r out of range
    while(!dq.empty() && dq.front()>i+k) dq.pop_front();
    int g=dp[dq.front()]+arr[i];
    // now push back this indice  to dequeue if u find any min value then this value pop
    while(!dq.empty() && dp[dq.back()]<=g) dq.pop_back();
    dq.push(i);
    dp[i]=g;
   
}
cout<<dp[0];// time complexity -O(n)

Round 2(1hr): Started with the interviewer’s Intro and then mine. Then he asked me about my project. Later a Question.

Recursive approach:




int func(int start, int end, vector<int>& arr, int k)
{
     if(k==0) return 0;
     return max( arr[start]+func(start+1,end,arr,k-1), arr[end]+func(start,end-1,arr,k-1);
}
cout<<func(0,n-1,arr,k);

Sliding window approach:




// indirectly we have to find total_Sum_of_array - minumum_sum_of_subarray_of_length_n-k
 
int total_sum=0;
int min_sum=INT_MAX;
int current_sum=0; //current sliding window
int g=n-k;
for(int i=0; i<n; i++)
{
    total_sum+=arr[i];
    current_sum+=arr[i];
    if(i-g>=0) current_sum-=arr[i-g];
    if(i>=g) min_sum=min(min_sum, current_sum);
}
cout<<total_sum-min_sum;

I have coded each of these approaches.

Recursive approach:




int func(int st, int end,  int k, vector<int>& arr,  vector<int>& val)
{
    int i=st+(n-1-end);
    //we are removed i elements already
    if(i==k) return 0;
    int left=func(st+1,end,k,arr,val)+(arr[st]*val[i]);
    int right=func(st, end-1, k,arr,val)+(arr[end]*val[i]);
    return max(left, right);
}
cout<<func(0,n-1,k,arr,val);

DP approach:  memorization




// 2d dp[n][n] inital values of -1
int func(int st, int end,  int k, vector<int>& arr,  vector<int>& val, vector<vector<int>>& dp)
{
    int i=st+(n-1-end);
    //we are removed i elements already
    if(i==k) return 0;
    if(dp[st][end]!=-1) return dp[st][end];
    int left=func(st+1,end,k,arr,val)+(arr[st]*val[i]);
    int right=func(st, end-1, k,arr,val)+(arr[end]*val[i]);
    return dp[st][end]=max(left, right);
}
cout<<func(0,n-1,k,arr,val,dp);

The interviews came to an end after this. There was no separate HR round. Finally I was selected for the role.


Article Tags :