MakeMyTrip Interview Experience | Set 5 (Online Coding)
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
If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Login to comment...