Open In App

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

Last Updated : 05 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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.

  • Given an array consisting of integers of size n and number k. Starting at the 0 indexes, you have to reach the n-1 index by jumping. if you are at index I, then u can jump to any index between i+1 to i+k.  when u jump on the index, arr[i] is added to ur sum. the problem is to find the maximum sum when u start at index 0 and reach n-1.

I have coded each of these approaches.

 Recursive approach:  

C++




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:

C++




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:

C++




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:

C++




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.

  • Given an array of integers of size n and a number k. We have to remove one number either from the leftmost or rightmost element from an array. repeat it k times. we have to find the maximum sum of these k numbers. ( question link )
  • I have coded each of these approaches.

Recursive approach:

C++




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:

C++




// 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;


  • The question is the same as above but with a slight change. Another array value of length k is given. while removing the number from the array, we have to multiply with this number. if we remove i1, i2.. ik indices from the array  then we have to find maximum value of this arr[i1]*value[0]+arr[i2]*value[1]+arr[i3]*value[2]…arr[ik]*value[k-1];

I have coded each of these approaches.

Recursive approach:

C++




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

C++




// 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.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads