Amazon Interview Question for Development Support Engineers


Country: United States
Interview Type: Phone Interview




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

cat time.txt | cut -d':' -f2- | awk  '{system("date +\"%s\" --date=\"" $0 "\"")}' | sed 'N;s/\n/-/;s/.*/echo \$((&))/e'

- raghu.aok December 06, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Input is as below ::
START TIME:2015-12-01 04:13:15
END TIME:2015-12-01 04:12:15
START TIME:2015-12-01 04:12:15
END TIME:2015-12-01 04:10:15

I haven't taken exact input as given in the question because i don't want to give the exact answer. Small changes are needed for the above input

- raghu.aok December 06, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I got the exact answer, thank you very much Raghu.
Can you please explain it , since it is little bit confusing

- Srinivas December 06, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

IF you want to remove the sed in the end , you can try this too

cat abc |cut -d':' -f2- | awk '{system("date +\"%s\" --date=\"" $0 "\"")}' | paste -d"-" - - | bc
60
120

- Hitesh February 01, 2016 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

cat abc |cut -d':' -f2- | awk  '{system("date +\"%s\" --date=\"" $0 "\"")}' | paste -d"-" -  - |  bc
60
120

- Hitesh February 01, 2016 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

cat abc |cut -d':' -f2- | awk  '{system("date +\"%s\" --date=\"" $0 "\"")}' | paste -d"-" -  - |  bc
60
120

- Hitesh February 01, 2016 | Flag
Comment hidden because of low score. Click to expand.
-2
of 4 vote

c++, implementation

#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <string.h>

using namespace std;

typedef long long INT64;

INT64 getDiff(string startTime, string endTime) {
	string command = "date +%s -d ";
	char cmd[256];
	char buf[256];
	FILE *ptr;
	INT64 start, end;
	int i;

	startTime = command + "'" + startTime + "'";
	strcpy(cmd, startTime.c_str());
	if ((ptr = popen(cmd, "r")) != NULL) {
		while (fgets(buf, 256, ptr) != NULL) {
			start = 0;
			i = 0;
			while (buf[i] >= '0' && buf[i] <= '9') {
				start = start * 10 + (buf[i] - '0');
				i++;
			}
		}

		fclose(ptr);
	}
	
	endTime = command + "'" + endTime + "'";
	strcpy(cmd, endTime.c_str());
	if ((ptr = popen(cmd, "r")) != NULL) {
		while (fgets(buf, 256, ptr) != NULL) {
			end = 0;
			i = 0;
			while (buf[i] >= '0' && buf[i] <= '9') {
				end = end * 10 + (buf[i] - '0');
				i++;
			}
		}

		fclose(ptr);
	}

	return end - start;
}

void findHighestTimeDifference(string filename) {
	ifstream inFile(filename.c_str());
	string startTime, endTime, maxStartTime, maxEndTime;
	INT64 diff, maxDiff;
	char buffer[256];
	int i;

    while(!inFile.eof()){
            inFile.getline(buffer, 100);
			string str(buffer);
			if (str.substr(0, 10).compare("STARTTIME:") == 0) {
				startTime = str.substr(10, str.size() - 10);
			} else if (str.substr(0, 9).compare("ENDTIME :") == 0) {
				endTime = str.substr(9, str.size() - 9);
				diff = getDiff(startTime, endTime);

				if (maxStartTime.size() == 0 || maxDiff < diff) {
				    maxStartTime = startTime;
				    maxEndTime = endTime;
				    maxDiff = diff;
				}
			}
    }
    inFile.close();
    
    cout << "STARTTIME:" << maxStartTime << "\n";
    cout << "ENDTIME :" << maxEndTime << "\n";
}

int main()
{
	findHighestTimeDifference("time.log");
	
	return 0;
}

- kyduke December 04, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The question is asking a single Unix command

- davie.lin76 December 05, 2015 | Flag


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