Below questions were asked in the screening round to code for in 30 minutes, though it took me 45 minutes to write the below code. Though it is suggested in the problem not to use any library function, so you can write your own code for binary search or sorting the array. But I can't understand the reason to reinvent the wheel here, this way these companies don't hire the learned people but educated donkeys.
Question : Write code to merge one sorted and one unsorted string arrays into one sorted array.
Sample
Array 1 -> {“a”,”c”,“d”,”f”,”g”}
Array 2 -> {“e”,”b”,”h”}
Final array to be printed -> {“a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”}
Answer :
Question : Write code to merge one sorted and one unsorted string arrays into one sorted array.
Sample
Array 1 -> {“a”,”c”,“d”,”f”,”g”}
Array 2 -> {“e”,”b”,”h”}
Final array to be printed -> {“a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”}
Answer :
Merging
Question : Identify bugs/corner cases in below mentioned code snippet and fix them. Please enhance the code with error/exception handing. Please share the final code through email.
public boolean redeemPoint(String customerId, String amount)
{
Double toRedeem = Double.valueOf(amount);
double currentPoints = myService.getPoints(customerId);
double newPoints = currentPoints - toRedeem;
myService.save(customerId,newPoints);
log.info("Points redeemed for customer {}",customerId);
return true;
}
Answer : Above question is another classic example of height of insanity of the interview questions. Means no context, class information etc, but tell the corner cases & issues.
public boolean redeemPoint(String customerId, String amount)
{
Double toRedeem = Double.valueOf(amount);
double currentPoints = myService.getPoints(customerId);
double newPoints = currentPoints - toRedeem;
myService.save(customerId,newPoints);
log.info("Points redeemed for customer {}",customerId);
return true;
}
Answer : Above question is another classic example of height of insanity of the interview questions. Means no context, class information etc, but tell the corner cases & issues.