TATA ELXSI Off Campus Coding Question

In this post we will see off campus coding questions asked in TATA ELXSI off campus recruitments. Various coding problems asked in tata elxsi off campus recruitment.

TATA ELXSI Coding Question


Given an integer array and integer N denoting array length as input, your task is to return sum of 3rd largest element and 2nd minimum element from array of elements.

Note: Input array can have negative elements as well


Input1: 9

input2: {8,10,8,4,15,9,6,3,17}

Output: 14

Explanation: from input2 we can see first highest number is 17, second highest number is 15, third highest number is 10

Also first minimum number is 3, second minimum number is 4.

Therefore “3rd highest number” + “2nd minimum number“= 10+4= 14

Algorithm For Solving TATA ELXSI problem

  1. Get the first input from user, that is value of N indicating number of elements in array
  2. Get second input from user indicating different values inside array.
  3. Sort the array in Ascending order or Decending order
  4. If sorted in ascending order select element at index position 2 for getting 3rd largest number.
  5. Then select element at index (last index-1) to get 2nd minimum element
  6. If sorted in Decending order decide accordingly for getting 3rd and 2nd elements from array.
  7. So now add up both selected elemets ehich is our answer


import java.util.*;
public class problem33 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(;
        System.out.println("Enter the number of elements ");
        int N=sc.nextInt();
        int array1[]=new int[N];
        int array2[]=new int[N];
        int k=0;
        System.out.println("Enter array elements ");
        for(int i=0;i<N;i++){
        for (int j = 0; j < array1.length - 1; j++) {
            if (array1[j] < array1[j + 1]) {
                int temp = array1[j];
                array1[j] = array1[j + 1];
                array1[j + 1] = temp;
                j = -1;
        int res=0;
        System.out.println("sum of 3rd largest and 2nd minimum element is : "+res);       

If you want step by step explanation for above code, watch our video below

Leave a Comment

Your email address will not be published. Required fields are marked *