Amazon Interview Question for SDE1s


Country: India
Interview Type: Written Test




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

cat file | awk -F"," '{print $(NF-1)}'

Output:

$ cat file.txt | awk -F"," '{print $(NF-1)}'
e
3
y

- Felipe Cerqueira February 08, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* 
First - the standard way 
*/
for( file('my_csv_file.csv') ) { 
  x = $.split(',') 
  println( size(x) > 1 ? x[-2] : '' ) 
}
/* The shell way:
unix.stackexchange.com/questions/17064/how-to-print-only-last-column
 */

- NoOne February 08, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void main()
{
        ArrayList <String> arrayList = new ArrayList<String>();
        arrayList.add("a,b,c,d,e,f");
        arrayList.add("1,2,3,4");
        arrayList.add("w,x,y,z");
        String result = new String();
        for(String getS : checkBeforeFinal(arrayList)){
            result = result + getS + "\n";
        }

        System.out.print(result);
}

private ArrayList<String> checkBeforeFinal(ArrayList<String> input){
        ArrayList<String> finalRetVal = new ArrayList<String>();
        String retVal = null;
        String charBeforeComma = null;

        for(int i=0; i< input.size(); i++){

            String getStr = input.get(i);
            for(int j=0; j < getStr.length(); j++){
                char getChar = getStr.charAt(j);
                String compare = String.valueOf(getChar);
                if(!compare.equals(",")){
                    charBeforeComma = String.valueOf(getChar);
                }else{ // the char is comma
                    // reset charBeforeComma
                    retVal = charBeforeComma;
                    charBeforeComma = null;
                }
            } // end of for j
            finalRetVal.add(retVal);
        } // end of for i
        return finalRetVal;
    }

- mannerh1 February 16, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.BufferedReader;
import java.io.File;

import java.io.FileReader;


public class Challenge3 {

public static void main(String[] args) {
try{
File f1=new File("test.txt");
FileReader freader=new FileReader(f1);
BufferedReader buffer=new BufferedReader(freader);
String value;
while((value=buffer.readLine())!=null){
String[] charArry=value.split(",");
System.out.println(charArry[charArry.length-2]);

}



}catch(Exception e){

e.printStackTrace();
}

}

}

- poola.praveen February 16, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

inputstr = []
inputstr.append('a,b,c,d,e,f')
inputstr.append('1,2,3,4')
inputstr.append('w,x,y,z')

def lastbutone(inarr):
      for l in inarr:
            print(l.split(',')[-2])

lastbutone(inputstr)

- Joy February 17, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

cat file.txt | awk '{if (NF -1 > 0)  print$(NF-1)}'

- Manish Prakash February 21, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

awk -F, '{print $(NF - 1)}' <filename>

- kathyaini August 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

rev file.txt | cut -d ', ' -f2

- Anonymous September 18, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

grep -o  '[,][a-z0-9][[:space:]]*$' File_name

- Vaibhav November 23, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

ghg

- fg November 23, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

grep -o  '[,][a-z0-9][[:space:]]*$' file_name

- kmickey.1992 November 23, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

cat file_name|rev|cut -d "," -f2

- Suman March 22, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

rev passwd_BKP | cut -d ":" -f2 | rev

- Sidd July 01, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

rev comma.txt | cut -d "," -f 2

- rg665n July 14, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sed 's/.*,\(.*\),.*$/\1/' filename

- Kunal April 07, 2019 | 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