Open In App

MakeMyTrip Interview Experience | Set 5 (Online Coding)

Improve
Improve
Like Article
Like
Save
Share
Report

Question 1: Given an array with n elements consisting of numbers between 1 to n-1 with some numbers being repeated multiple times in the array.
Give a result[] array as output containing all the repeated/duplicate elements.




Code:   package arrays;
=====
import java.util.ArrayList;
  
public class MultipleDuplicateValues {
  
    public static void main(String[] args) {
  
        int arr[] = { 1, 2, 3, 1, 3, 6, 6 };
        int[] result = getduplicates(arr);
        for (int i = 0; i < result.length; i++) {
            System.out.println(Math.abs(result[i]));
        }
  
    }
  
    private static int[] getduplicates(int[] arr) {
        ArrayList<Integer> l = new ArrayList<Integer>();
        int[] result;
        for (int i = 0; i < arr.length; i++) {
            if (arr[Math.abs(arr[i])] >= 0) {
                arr[Math.abs(arr[i])] = -arr[Math.abs(arr[i])];
            } else {
                l.add(arr[i]);
            }
  
        }
  
        result = new int[l.size()];
        int i = 0;
        while (i < l.size()) {
            result[i] = l.get(i);
            i++;
        }
  
        return result;
    }
}


Question 2: Given an array containing a sequence of numbers , you need to identify whether that sequence is Fibonacci , Arithmetic Expression or Geometric Expression
============ And give it’s next term as output.

Total time for the above two questions : 45 Minutes

Mode of interview : Online Coding



Last Updated : 21 Mar, 2015
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads