Monday 17 August 2015

Survey Analysis

Standard
WebEngage empowers companies to collect feedback and gather insights from visitors using survey and notifications.
An e-commerce company used the WebEngage customer engagement tool to ask visitors if they want to buy the selected products at discounted prices. If the visitor said 'Yes', the product was delivered to the customer at the discounted price. They collected the response for a whole week from Monday to Sunday. Now they want to analyse which day most of the people said 'Yes' compared to other days. For this, they want to calculate the standard deviation of the 'Yes' count on each day. Using the standard deviation, we have a standard way of knowing which day was extra good, which day was extra bad, and which day was just plain normal in terms of business.
Input format
The input contains 7 lines, depicting Monday to Sunday. Each line contains a string of 1 & 0. 1 means the visitor said 'Yes', and 0 means the visitor said 'No'.
Output format
Output a single line with the result rounded to 4 decimal places, which is the standard deviation of the 'Yes' count on each day.
Input constraint
Number of visitors everyday doesn't exceed 1 million.

Sample Input
11011
1010000
0010
1101
010
101111
001110
Sample Output
1.3851

Time Limit: 2 sec(s) for all input files combined.
Memory Limit: 256 MB
Source Limit: 1024 KB 
 
Code: 
 
import java.util.Scanner;


class TestClass {
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        String perDaySurvery = null;
        long yesPerWeek[] = new long[7];
        double squareOfDiff = 0;
        double avg = 0;
        for(int i=0;i<7;i++)
        {
            long yesPerDay = 0;
            perDaySurvery  = sc.next();
            long inputLength = perDaySurvery.length();
            for(long j=0;j<inputLength;j++)
            {
                if(perDaySurvery.charAt((int) j)== '1'){
                    yesPerDay++;
                }
            }
           
            yesPerWeek[i] = yesPerDay;
            avg+=yesPerWeek[i];
        }
        avg = avg/7;
        for(int i=0; i<7; i++)
        {
            squareOfDiff += (yesPerWeek[i]- avg)*(yesPerWeek[i]- avg);
        }
        avg = squareOfDiff/7;
       
       
        System.out.printf("%.4f",(Math.sqrt(avg)));
   
    }

0 comments:

Post a Comment