Flipkart Interview Question for Software Analysts


Country: United States
Interview Type: In-Person




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

The key is to realize A and M operations can be delayed until you need to calculate the final result. For example, the operation sequence AAMAM (X=1,Y=2) is equal to a single step calculation to the original item a which is: a*4+10. So in the ith operation, you only have to calculate the ith element's final value and update the single step calculation according to the ith operation.

And when the ith operation is R, what we should do is starting to swap the ith to nth elements one pair per operation (ith and nth, i+1th and n-1th) and apply the single step calculation to the new ith element and move on. If no new R, just keep swapping. When we encounter another R in position j. We should stop the previous swapping and begin a new one from jth to nth.

- lniniaa January 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Ininiaa Could you provide code in c++/java.?Thanx in advance

- justhack4fun688 January 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

It must be something like this:

mul=1;
add=0;
swap=false;
swap_ptr=0;

for i from 0 to n-1
{
	if (op==A) {add+=X;}
	if (op==M) {mul*=Y; add*=Y;}
	if (op==R) {
		swap (array[i], array[n-1]);
		swap=true;
		array[i]=(array[i]*mul+add) mod Z;
		swap_ptr=2;
		continue;
	}
	if (swap==true)
		if (i<n-swap_ptr)
			swap (array[i], array[n-swap_ptr++]);
		else {
			swap==false;
		}
	array[i]=(array[i]*mul+add) mod Z;
}

- lniniaa January 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Ininiaa Why u set swap_ptr to 2 here?And how are you sure that on your first step the add and mult will not overflow as the caluclation can go upto 10^18.

- justhack4fun688 January 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

If op==R, we swap ith and n-1th, next time we need to swap i+1th and (n-swap_ptr) which is n-2th.

- lniniaa January 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Ininiaa and wht about avoiding overflow?

- justhack4fun688 January 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

(a*b) mod Z = (a mod Z)*(b mod Z). The function can surely be refined.

- lniniaa January 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

@Ininiaa I am not saying about this.i am talking about if (op==A) {add+=X;}
if (op==M) {mul*=Y; add*=Y;}
Here there is no mod operation

- justhack4fun688 January 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Reversing array from i , i+1 with N , N-1 ... and then j , j+1 , j+2.. with N , N-1 .. is not giving correct result

- Savi January 09, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Please dont reply... Its a question of an ongoing online coding competition...

- kira January 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Another question from running codding competition:
codechef.com/JAN14/problems/MTRICK
Someone is cheating.

- Anonymous January 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

What lenght sequence could be? First of all idea is that addition and multiplication are associative , also a * b == b * a. If you've got only A and M you could compute X * count A mod Z and Y ^ countM mod Z very fast. But R brokes it over. So you can do this fast computation of addition on multiplication between R operations. Example

AMMARAARMAMAAA
transorm to

first block R second block R third block

R destroys concurrency, you need to compute all blocks sequentially. But inside of them addition and multiplication are independent.

- glebstepanov1992 January 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@glebtstepanov1992 Length of sequence is also n(=length of array).And how to do compute blocks as for ith operation we need to change elements from i to n. rather than all elements of array.

- justhack4fun688 January 05, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Another question from running codding competition:
codechef.com/JAN14/problems/MTRICK
Someone is cheating.

- Anonymous January 05, 2014 | 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