Question: Zscaler on Campus Assosciate Software Engineer | 12-08-2020
2
Entering edit mode

Zscaler visited on 12th august 2020 CTC 17 LPA Online Round 4 coding questions (only C Language allowed) The questions were pretty straight forward The only tricky part was you needed to implement your own sort and hashing functions

Around 20 were shortlisted from 600 candidates.

Interview Round 1

Started with rapid fire of OS/CN/OOPS and then 2 coding questions :-

  • Given an array of size N, find minimum of every contagious subarray of K length
Click here to Practice
  • Given an array of size N, for every index find its next greater element

Interview Round 2

The interviewer began with "I have received a feedback from previous interviewer that you are good at problem solving so we will do 1 coding question and if you do good you will make it."

Here is the one question we discussed:-

  • Given a string, write a function to compress it by shortening every sequence of the same character to that character followed by the number of repetitions.

Sample Input

aabbccaaa

Sample Output

a2b2c2a3

I got stuck on an edge case and alas rejected.

They finally made offers to 2 students.

1
Entering edit mode

Question 1 (Round1)

Overview

  • Given an array A of size n
  • For every contiguous subarray of size k, we have to find the subarray with the minimum sum.

Approach

  • We can get all the subarrays of size k and get their sum, the time complexity would be O(nk)
  • To optimize this, we can see that sum of a particular window can be found in O(1) if we have the sum of the previous window using, S(new)=S(old)+A[k+1]-A[0]
  • We can use this to get the sum of all windows and then get the minimum.

Time Complexity

  • O(n)

PseudoCode

int curr=0;
int min_sum =    INT_MAX;
for(int i=0;i < k;i++){
    curr+=a[i];
}
min_sum=min(curr,min_sum);
for(int i=k;i < n;i++){
    curr-=a[i-k];
    curr+=a[i];
    min_sum=min(curr,min_sum);
}
ADD COMMENTlink 23 months ago Harsh Priyadarshi 70
0
Entering edit mode

answer for question 2;

public String compress(String s) {

    String out = “”;

    int sum = 1;

    for (int i = 0; i < s.length() - 1; i++) {

        if (s.charAt(i) == s.charAt(i+1)) {

            sum++;

        } else {

            out = out + s.charAt(i) + sum;

            sum = 1;

        }

    }

    out = out + s.charAt(s.length() - 1) + sum;

    return out.length() < s.length() ? out : s;

}

ADD COMMENTlink 14 months ago Yash Hegde • 0

Login before adding your answer.

Similar Posts
Loading Similar Posts