Pergunta de entrevista da empresa Amazon

Q1: You have been given an Array of Strings and you have to find out which string occurrence is maximum. If there is a tie then take the last string. For eg: input = {cat, dog, lion, cat, lion, dog, hen, cat, dog} then output = dog Q2: You have been given a error log file and you have to output the ERROR logs in between any two dates of the month. Q3: you have been given a text file: a) replace word Amazon with Andy in first 50 lines. b) replace word Amazon with Andy from 50th line till the last line. Q4: You have been given a table name world where you would have to output from table city if city is not null else output the table country.

Respostas da entrevista

Sigiloso

2 de nov. de 2022

Q2: You have been given a error log file and you have to output the ERROR logs in between any two dates of the month. $cat file_name | grep "error" | sed -n '/pattern1/ , /pattern2/p' eg: cat abc.log | grep "ERROR" | sed -n '/Oct 13 10:10:10/ , /Oct 15 11:11:11/p' I hope it helps.

2

Sigiloso

2 de nov. de 2022

Q3: you have been given a text file: a) replace word Amazon with Andy in first 50 lines. b) replace word Amazon with Andy from 50th line till the last line. a. $ head -50 file_name | sed 's/Amazon/Andy/' > new_file_Name file_path b. $ tail -n +50 file_name | sed 's/Amazon/Andy/' >> new_file_Name file_path

Sigiloso

2 de nov. de 2022

Q1. You have been given an Array of Strings and you have to find out which string occurrence is maximum. If there is a tie then take the last string. For eg: input = {cat, dog, lion, cat, lion, dog, hen, cat, dog} then output = dog Code: #include using namespace std; int main() { string input[] = {"cat", "dog", "lion", "cat", "lion", "dog", "hen", "cat", "dog"}; int n= sizeof(input) / sizeof(input[0]); int freq=0; string res; for(int i=0; i= freq) { res=input[i]; freq= count; } } //end of i loop cout<<"Element is: " <