0% found this document useful (0 votes)
27 views

Java Developer-SDE Coding Assignment Q1

The document provides instructions for a written coding test for Amazon. It outlines that candidates have 45 minutes to complete the test. They can use any programming language and should avoid library functions for the coding question. Once completed, candidates should zip their code and artifacts and email it back within the time limit. The test contains two coding questions - the first asks to merge one sorted and one unsorted string array into a single sorted array, and provides a sample input and output. The second asks to identify bugs and corner cases in a provided code snippet that redeems reward points, and fix them while adding error handling. Candidates are instructed to email their final code for the second question.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Java Developer-SDE Coding Assignment Q1

The document provides instructions for a written coding test for Amazon. It outlines that candidates have 45 minutes to complete the test. They can use any programming language and should avoid library functions for the coding question. Once completed, candidates should zip their code and artifacts and email it back within the time limit. The test contains two coding questions - the first asks to merge one sorted and one unsorted string array into a single sorted array, and provides a sample input and output. The second asks to identify bugs and corner cases in a provided code snippet that redeems reward points, and fix them while adding error handling. Candidates are instructed to email their final code for the second question.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Duration: 45 mins.

Amazon Written Test


Instructions
1. You may use any language to write code.
2. Please avoid using library functions for the coding question.
3. Once you are done, or after 45 minutes, please zip your code and other artefacts and share mail it back to
us. Any solutions reaching post 45(max 50) minutes mark will be disqualified
4. Please make sure your code is of production quality and handling all scenarios/edge cases.

Questions
Q1: 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”}
public class HelloWorld {
public static void main(String args[]) {
String arr1[]={"a","c","d","f","g"};
String arr2[]={"e","b","h"};
StringBuffer sb = new StringBuffer();
for(int i=0;i<arr1.length;i++){
sb.append(arr1[i].charAt(0));
}
for(int i=0;i<arr2.length;i++){
sb.append(arr2[i].charAt(0));
}
System.out.println(sb);
char ch[] = new char[sb.length()];
for(int i=0;i<sb.length();i++) {
ch[i] = sb.charAt(i);
}
for(int i=0;i<ch.length-1;i++) {
for(int j=0;j<ch.length-1;j++) {
if(ch[j]>ch[j+1]) {
char temp = ch[j];
ch[j] = ch[j+1];
ch[j+1] = temp;
}
}
}
sb.delete(0, sb.length());
String str = sb.append(ch).toString();
System.out.println(str);
}
}

Q2: 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);

1
Duration: 45 mins.

double currentPoints = myService.getPoints(customerId);


double newPoints = currentPoints - toRedeem;
myService.save(customerId,String.Value of(newPoints));
log.info("Points redeemed for customer {}",customerId);
return true;

You might also like