Flipkart Interview Question for Software Developers


Country: India




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

avg=2B

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

what is B here

- pbox August 19, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

avg=2B

- Anonymous August 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Before starting the running average create this:

StreamingAverage avg = new StreamingAverage();

Every time a new number is pulled from the stream, call this:

avg.addToAverage(number);

Here's the code supporting it:

public class StreamingAverage{
    int count = 0;
    double average = 0;

    public void addToAverage(int number){
        double workingAverage = this.average * this.count;
        this.count ++;
        workingAverage += (double)number;
        this.average = workingAverage / (double)this.count;
    }

    public double getAverage(){
        return this.average;
    }
}

- zortlord August 19, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

you can't store count because you are not allowed to sore any value more than 2 digits
this.count ++;//you are not allowed
here is also problem due to multiplication
double workingAverage = this.average * this.count;

- pbox August 19, 2015 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

@pbox
If you can't store anything other than the 2 digits holding the running average, then your problem is impossible. If you lack the memory to hold more than 2 digits of information, then you surely can't create supportive objects or very much code either.

- zortlord August 20, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Feeling like this is impossible with single variable.

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

Feeling likes its impossible with single variable.

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

Seems imposible

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

It seems right question is to figure out median not average. In that process we can store them in 2 heaps, one in ascending and other one is descending. This question is available on site.

- Phoenix September 09, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

avg +=num/2;

- Prem Bharti November 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

seems like ok, can you prove it mathematically for more numbers as given in the problem statement

- disha November 07, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Seems like ok, can you proove it mathematically?

- Disha November 07, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

If the input is : 10, 12, 20
Your formula gives 21 which is wrong.

- krgaurav22 December 20, 2015 | Flag


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