Search This Blog

Wednesday, April 9, 2014

Algorithms - Warmup - Halloween party

Halloween party

The following is the solution to Hacker Rank problem Halloween party using Java.  For solutions to other Hacker Rank Problem visit my page HackerRank, alternatively try searching for the problem in my blog.

Score: 20/20
/**
 *
 */


import java.util.*;

/**
 * @author Arun.G
 *
 */
public class Solution{

       public static long noOfChocolates(int k) {
              long noOfChocolates = 0;

              noOfChocolates = (long) (k / 2) * (k - (long) (k / 2));
              return noOfChocolates;
       }

       public static void main(String[] args) {
              /*
               * Enter your code here. Read input from STDIN. Print output to STDOUT.
               * Your class should be named Solution.
               */
              Scanner sc = new Scanner(System.in);
              int T = sc.nextInt();
              // T Test Cases to handle
              for (int i = 0; i < T; i++) {
                     int k = sc.nextInt();
                     System.out.println(noOfChocolates(k));
              }
              sc.close();
       }
}

No comments:

Post a Comment

Labels