Amazon Interview Report
- 0of 0 votes
AnswersA log file is of below format
log.txt
=====================================
TIMESTAMP:MM-DD-YYYY
REQUEST:______________________________
RESPONSE:____________________________
SUCCESS:200:________________________
=====================================
TIMESTAMP:MM-DD-YYYY
REQUEST:______________________________
RESPONSE:____________________________
ERROR:400:________________________
=====================================
TIMESTAMP:MM-DD-YYYY
REQUEST:______________________________
RESPONSE:____________________________
ERROR:=500:________________________
=====================================
TIMESTAMP:MM-DD-YYYY
REQUEST:______________________________
RESPONSE:____________________________
ERROR:400:________________________
=====================================
TIMESTAMP:MM-DD-YYYY
REQUEST:______________________________
RESPONSE:____________________________
ERROR:401:________________________
I want the count of error between two given dates.
- anushvenki May 12, 2013 in Indiagrep '0[6789]:\| 1[01234567]' | ""grep -c "ERROR" log.txt timestamp = grep "TIMESTAMP" awk '$timestamawk>=from&&$timestamp<=to' from="2007/03/20 15:13" to="2007/08/19 14:31" log.txt | grep "ERROR" | wc -l timestamp = grep "TIMESTAMP" echo timestamp | awk -F'[- ]' '$2 >= 25 && $3 <= 04 { print }' | grep -c "ERROR"
| Report Duplicate | Flag | PURGE
Amazon Applications Developer Unix - 0of 0 votes
AnswersFind the maxProduct of three numbers from a given integer array.
1. Handle all the cases
2. Interviewer was looking for a complete code
- anushvenki May 12, 2013 in Indiapublic int maxPro() { // -5, -4, -3, -2 , 0 Int array[] = new Int[]{4,5,6,0,-5,-7,-2,-10}; Arrays.sort(array); // -10,-7,-5,-2,0,4,5,6 int count =0; for(int i =0; i<array.length();i++){ if(array[i]<0) count = count+1; } int maxProduct =1; if ( array.length()<3){ return -1; } else if( array.length()>=3 ){ int a=1; b=2; if(count>=2){ a = array[0]*array[1]*array[array.length-1]; b = array[array.length-1]*array[array.length-2]*array[array.length-3]; maxProduct = Math.max(a,b); } else if (count == 0 || count == 1 || count == array.length()){ maxProduct = array[array.length-1]*array[array.length-2]*array[array.length-3]; } } return maxProduct; }
| Report Duplicate | Flag | PURGE
Amazon Applications Developer Coding - 0of 0 votes
Answersgiven an array of charactes have to replace space with %20. where %20 is considered as 3 characters.write complete code to implement this.
ps: assume that array has enough space at the end that can fit one space character to 3 chacters(%20).
- anushvenki May 12, 2013 in Indiaimport java.io.* char fn(char [] word) { for(int i =1;i<=word.length();i++) { if(char[i]==" " && isArrayRightShiftable(word)){ shiftArrayToRight(word,i); char[i]='%'; char[i+1]='2'; char[i+2]='0'; } } return word; } private boolean isArrayRightShiftable(char[] word) { if(word.length()+2 < 50){ return true; } return false; } private void shiftArrayToRight(char[] word, int i) { for(int j = word.length();j>=i;j--) word[j+2]=word[j]; }
| Report Duplicate | Flag | PURGE
Amazon Applications Developer Problem Solving