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)));
   
    }

Related Posts:

  • Rasta and Tavas Rasta calls a number like a Tavas if and only if 1 ≤ a ≤ n and the sum of all primes (like p) that p | a is exactly equal to k. He asks you to find … Read More
  • Rasta and Darie A Darie is a special circle. Numbers 1, 2, ..., n are written clockwise around this circle in order. You can stand on a number! Initially Rasta is on… Read More
  • Birthday Party My flatmate, Sayan, once invited all his relatives and friends from all over the city to join him on his birthday party. He is also famous for boast… Read More
  • Small Factorials Problem You are asked to calculate factorials of some small positive integers. Input An integer T, denoting the number of testcases, followed by T lines, e… Read More
  • Rasta and Kheshtak Rasta is a big fan of Kheshtaks. A Kheshtak is a rectangle that in each of it cells there is an integer. Today rasta came up with an interesting pro… Read More

0 comments:

Post a Comment