Saturday, March 4, 2017

Programming Questions

1. Write a program for sprinter to complete the race. Input function is like this:
hurdles = { 2, 3, 4, 7, 2} capacity=5
Sprinter can jump hurdle if hurdle value is <= capacity, if the hurdle value > capacity then the sprinter needs to call a function which increases capacity by 1, write code for the sprinter to complete the race.

2. There is is a multi dimensional array/matix of 3X3 size, which has integer values. where ever you find 0 in the array then you need to make all the elements in that ROW and Column as 0. Write code for this.
3. Find first largest and second largest in the array.
4. there is an array {2,4,6,8,3}. Take out one element and add others, take out 2nd one and add others...  we need to find the largest sum of remaining numbers.
Approach 1: sort the array using Collections.sort(arr), take out the first element and add other elements, then we get largest sum.
Or find out smallest element of the array, take it out and add the remaining.
5. What is singleton class. How do we prevent the it's object from serializing and cloning.
6. Find the duplicate elements in an array.
hint: use solution using XOR operation.