Netflix Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

Load file data in memory as per it's capacity, say x% of total file.Now keep printing the given percentage of x, and remove the printed data from memory. Keep doing this till you read complete file, and at the end of it you will have read the given percentage.

- OTR August 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

'Should not be same'? What if it has 2 bytes, percentage is 50% and you call it a 100 times?

Perhaps you mean it should be 'random'?

- Anonymous August 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I agree. 'should not be same' can be achieved through randomness. I gave the interviewer the same answer. I told him that I would have a helper function within the function to give me a list of random numbers.

I forgot to mention in the question that he asked me assume that the file is all numbers. Each line would be some number.

- RockStar August 16, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

read the number of letters in the file and find the given percent of the counted number of letters, print the same. If the file is to be called multiple times, store output of calculation of given pecent of the counted number of letters and read the number of letters again starting from the last printed letter(which is the outcome of the given percent calculation on number of letters). find the given percent of the counted number of letters. This particular process can be written inside a loop.

- Toby August 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Following the Toby's suggestion, We can use hash table where the keys are the file names and the values are the character counts that are printed in the last reading of the file.

- Anonymous August 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use the linux's stat() to find the size of the file then read only required number of bytes.

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

1. Say, percent is given input from user.
2. Read 100 bytes from file
3. generate a random no. between 0 and 100-percent
4. Print percent bytes from randdom no.
5. Repeat this process untill you exhaust complete file.
6. In the last, bytes less than 100 will be read, adjust percent and random function accordingly.

- Mukesh August 21, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

void printFromFile(string fileName, int percentage) 
{
	char buf[100];
	ifstream infile( fileName );

	while( !infile.eof() )
	{
		infile.read( buf, 100 );
		int count = infile.gcount();
		int to_print = (percentage*100)/count;
		int start = rand() % (count - to_print + 1);

		for( int i = 0; i < to_print; i++ )
			cout << buf[start + i];
	}

	infile.close();
}

- Mukesh August 21, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

fseek(fp, 0, SEEK_END);
size = ftell(fp);

size will contain the size of the file. Now go back to beginning by fseek(fp,0, SEEK_BEG) and start reading bytes in chunks.

- Anonymous November 20, 2013 | 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