Amazon Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

need to break down the input and then reassemble the output in roman numerals keeping in mind the subtraction rule....i first broke down the input and recorded how many 1000, 500, 100, 50, 10, 1 's i have....then i generate an intermediate output in roman form from that and then i look at the intermediate output and apply the subtraction rule using regular expressions to find consecutive characters that are equal and replace them....according to rule you cannot have more than 3 I's...have a look at the rules on wikipedia by searching for 'roman numerals'

- chrysalis November 20, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="" line="1" title="CodeMonkey56971" class="run-this">public class RomanConversion {

// Parallel arrays used in the conversion process.
private static final String[] RCODE = {"M", "CM", "D", "CD", "C", "XC", "L",
"XL", "X", "IX", "V", "IV", "I"};
private static final int[] BVAL = {1000, 900, 500, 400, 100, 90, 50,
40, 10, 9, 5, 4, 1};

//=========================================================== binaryToRoman
public static String binaryToRoman(int binary) {
if (binary <= 0 || binary >= 4000) {
throw new NumberFormatException("Value outside roman numeral range.");
}
String roman = ""; // Roman notation will be accumualated here.

// Loop from biggest value to smallest, successively subtracting,
// from the binary value while adding to the roman representation.
for (int i = 0; i < RCODE.length; i++) {
while (binary >= BVAL[i]) {
binary -= BVAL[i];
roman += RCODE[i];
}
}
return roman;
}
}</pre><pre title="CodeMonkey56971" input="yes">class Main(String args[]) {
int number = 2468;
System.out.println(RomanConversion.binaryToRoman(number);
}</pre>

- Anonymous October 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The code has been picked up from:
roseindia.net/java/java-tips/45examples/misc/roman/roman.shtml

- Anonymous October 29, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The code has been picked up from:
roseindia.net/java/java-tips/45examples/misc/roman/roman.shtml

- Anonymous October 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The code has been picked up from:
roseindia.net/java/java-tips/45examples/misc/roman/roman.shtml

- Anonymous October 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The solution has been picked up from:
roseindia.net

- Anonymous October 29, 2011 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More