## Amazon Interview Question for SDE1s

Country: United States

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

Use whichever date/time method OS supplies. It will be updated to a functional version periodically.

Sample current time, extract month and year number. Extract month and year from supplied string as integers. Compare year against year, then month against month if necessary. Current year shall not be smaller than card year, if equal, current month shall not be smaller than card month.

What kind of question is this anyway? How do you even screw it up so it doesn't work in 100 years? That's the real question here.

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

Use whichever date/time method OS supplies. It will be updated to a functional version periodically.

Sample current time, extract month and year number. Extract month and year from supplied string as integers. Compare year against year, then month against month if necessary. Current year shall not be smaller than card year, if equal, current month shall not be smaller than card month.

What kind of question is this anyway? How do you even screw it up so it doesn't work in 100 years? That's the real question here.

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

r

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

public static boolean isValid(String date) {
java.text.SimpleDateFormat sm = new java.text.SimpleDateFormat("YYYY/MM");
String[] sms = sm.format(new java.util.Date()).split("/");
String[] dates = date.split("/");

try {

if(Integer.parseInt(dates[1] + dates[0]) < Integer.parseInt(sms[0] + sms[1])) return false;
else return true;
} catch (Exception e){
return false;
}
}

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

private static boolean isValid(String s){
boolean flag = false;
int MM = Integer.parseInt(s.substring(0,2));
int YY = Integer.parseInt(s.substring(2,4));
if (s.length() == 4 && MM > 0 && MM < 13 && YY >= 00)
flag = true;
return flag;

}

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

it need to work 100 years from now but the format is mmyy, if you use base 10 you can only encode 100 year but it won't be from now. it will work from xx00 to xx99 only with xx for our case is 20.
My solution will be to use a different base, for exemple base 16. we will have it working for 256 years from 00 with in our case in 2017 menas 249 years from now.

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