For two integer arrays, the comparator value is the total number of elements

Try the new Google Books

Check out the new look and enjoy easier access to your favorite features

For two integer arrays, the comparator value is the total number of elements


Page 2

Try the new Google Books

Check out the new look and enjoy easier access to your favorite features

For two integer arrays, the comparator value is the total number of elements


Page 2

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More

Even though there is something easy like .equals, I'd like to point out TWO mistakes you made in your code. The first: when you go through the arrays, you say b is true or false. Then you start again to check, because of the for-loop. But each time you are giving b a value. So, no matter what happens, the value b gets set to is always the value of the LAST for-loop. Next time, set boolean b = true, if equal = true, do nothing, if equal = false, b=false.

Secondly, you are now checking each value in array1 with each value in array2. If I understand correctly, you only need to check the values at the same location in the array, meaning you should have deleted the second for-loop and check like this: if (array2[i] == array1[i]). Then your code should function as well.

Your code would work like this:

public static void compareArrays(int[] array1, int[] array2) { boolean b = true; for (int i = 0; i < array2.length; i++) { if (array2[i] == array1[i]) { System.out.println("true"); } else { b = false; System.out.println("False"); } } return b;

}

But as said by other, easier would be: Arrays.equals(ary1,ary2);

Round 1 (Online Test): 10 MCQS (based on Aptitude, OS, OOP, Output based ques) + 2 Coding question

  1. Minimum Divisor: Given an array of integers, each element is to be divided by an integer so that the sum of results is less than or equal to a threshold integer. Each one-integer result of the division is rounded up before it is added to the sum. Determine the minimum divisor to make the sum less than or equal to the threshold.
  2. Reductor Array: For two integer arrays, the comparator value is the total number of elements in the first array such that there exists no integer in the second array with an absolute difference less than or equal to d. Find the comparator value.

Could solve all test cases for 2 coding ques and 8+ MCQs in 10 were right.

15 students got shortlisted for Interviews.

Round 2 (Technical Interview 1 Approx 80mins): Took place on HackerRank Code Pair.

  1. Started off with my introduction, followed by my internship discussion (which was in Data Science). Based on that I was asked to code on the IDE, where I had to save a .txt file in my laptop, import it and parse through the words and output the duplicate words along with their frequency count.
  2. The next task was to subtract 2 matrices is given specific constraints of space and time in the IDE. (cleared all test cases)
  3. I was then asked about Software Process Models, how is the unified process different from Waterfall and Incremental.
  4. Next was asked to demonstrate using code in IDE Run time and Compile time Polymorphism. Was expected to write an OverRiding Func with its use case. (needed to pass all test cases on hackerrank)

Round 3 (Technical Interview 2 Approx 65mins): This took place on MS Teams.

  1. Tell about Rest API.
  2. Tell about the difference in SOAP and REST APIs.
  3. Questions on Cloud Computing and its architecture.
  4. Was asked about HTTP Protocol and why most web pages are better coded in Java (Interpreted and Compiled language discussion)
  5. Was asked about Linked List and its various implementation (Unroll, skip list, etc) And how it differs from an array.
  6. Coding Ques 1: Given a Linked List of numbers (unsorted) find total combinations of numbers that give sum=K.
    Eg: List : 1->2->3->4->5->6->7->8->9->10 Sum K=10
  7. Coding Ques 2: Given an Array of Numbers, find the point in the array where LHS sum equals RHS Sum. Also, find the number of such points possibleEg: Array = 1,2,3,4,7,5,5 O/p: 7,1
  8. Given 2 variables, without using a comparison operator find which number is greater or lesser.
  9. OOP Concepts and Pass by value and Pass by Reference Implementation difference along with their codes
  10. A very general discussion on Trees and Graphs

After technical rounds, around 6/15 students made it to next round

Round 4 (Managerial Interview Approx 70mins): Focused mainly on my resume and my ambitions, took place on MS Teams.

  1. Why SAP?
  2. I was given a hypothetical situation of a client along with his requirements for the product and was expected to tell how I would lead the project along with the expected timeline.
  3. Was asked about Agile Manifesto and other process Models, and based on different situations was asked to pick between diff models.
  4. The interviewer wanted to know if I held any leadership position in life and have I ever accounted/managed large amounts of money for an organization.
  5. Do my values and beliefs fall in line with SAP?
  6. What were the implementation details and idea behind my Project (mentioned on my resume)
  7. Briefly discussed my GHCI Scholarship and what is my outlook to life on a broader perspective. (mentioned on my resume)
  8. Why do you want to join SAP Labs? Why not wait for other companies to come?

Round 5 (HR Interview Approx 30mins): It revolved around the conclusion of my previous round and how I am as a person, my interpersonal skills. Took place on MS Teams again.

  1. What are my interests?
  2. Do you have a problem with relocation? Where would you like to work?
  3. My internship experience and discussion on how my codes were pushed to production, what new algos I used there.
  4. Why I chose MIT Manipal, and what are my higher study ambitions.
  5. About my home town and where I see myself in a few years post-college.

Finally, they recruited 3 students for Full Time Employment Offer. I was selected as one of them.

Article Tags :

Given two arrays arr1[] and arr2[] and an integer K, our task is to find the number elements in the first array, for an element x, in arr1[], there exists at least one element y, in arr2[] such that absolute difference of x and y is greater than the integer K.

Examples: 

Input: arr1 = {3, 1, 4}, arr2 = {5, 1, 2}, K = 2 
Output:
Explanation: Such elements are 1 and 4. For 1, arr2[] has 5 and abs(1 – 5) = 4 which is greater than 2. 

For 4, arr2[] has 1 and abs(4 – 1) = 3 which again is greater than 2.

Input: arr1 = {1, 2}, arr2 = {4, 6}, K = 3 
Output:
Explanation: Such elements are 1 and 2. For 1, arr2[] has 6 and abs(1 – 6) = 5 which is greater than 3. For 2, arr2[] has 6 and abs(2 – 6) = 4 which is greater than 3. 

Naive Approach: Iterate for each element in arr1[] and check whether or not there exists an element in arr2 such that their absolute difference is greater than the value K. 

Time complexity: O(N * M) where N and M are the sizes of the arrays 1 and 2 respectively.

Efficient Approach: To optimize the above method we have to observe that for each element in arr1[], we need only the smallest and largest element of arr2[] to check if it is distant or not. For each element x, in arr1, if the absolute difference of smallest or the largest value and x is greater than K then that element is distant.

Below is the implementation of the above approach:  

void countDist(int arr1[], int n, int arr2[],

    for (int i = 0; i < m; i++) {

        smallest = max(smallest, arr2[i]);

        largest = min(largest, arr1[i]);

    for (int i = 0; i < n; i++) {

        if (abs(arr1[i] - smallest) > k

            || abs(arr1[i] - largest) > k)

    int arr1[] = { 3, 1, 4 };

    int n = sizeof(arr1) / sizeof(arr1[0]);

    int arr2[] = { 5, 1, 2 };

    int m = sizeof(arr2) / sizeof(arr2[0]);

    countDist(arr1, n, arr2, m, k);

static void countDist(int arr1[], int n,

    for(int i = 0; i < m; i++)

       smallest = Math.max(smallest, arr2[i]);

       largest = Math.min(largest, arr1[i]);

    for(int i = 0; i < n; i++)

       if (Math.abs(arr1[i] - smallest) > k ||

           Math.abs(arr1[i] - largest) > k)

public static void main(String[] args)

    int arr1[] = { 3, 1, 4 };

    int arr2[] = { 5, 1, 2 };

    countDist(arr1, n, arr2, m, k);

def countDist(arr1, n, arr2, m, k):

        smallest = max(smallest, arr2[i])

        largest = min(largest, arr1[i])

        if (abs(arr1[i] - smallest) > k

            or abs(arr1[i] - largest) > k):

if __name__ == '__main__':

    countDist(arr1, n, arr2, m, k)

static void countDist(int []arr1, int n,

    for(int i = 0; i < m; i++)

       smallest = Math.Max(smallest, arr2[i]);

       largest = Math.Min(largest, arr1[i]);

    for(int i = 0; i < n; i++)

       if (Math.Abs(arr1[i] - smallest) > k ||

           Math.Abs(arr1[i] - largest) > k)

public static void Main(String[] args)

    int []arr1 = { 3, 1, 4 };

    int []arr2 = { 5, 1, 2 };

    countDist(arr1, n, arr2, m, k);

function countDist(arr1, n, arr2, m, k)

        smallest = Math.max(smallest, arr2[i]);

        largest = Math.min(largest, arr1[i]);

        if (Math.abs(arr1[i] - smallest) > k ||

            Math.abs(arr1[i] - largest) > k)

countDist(arr1, n, arr2, m, k);

Time Complexity: O(N + M), where N and M are the sizes of the given arrays.
Auxiliary Space: O(1).
 


Article Tags :