Search This Blog

Saturday, September 28, 2013

Algorithm - Sorting - Counting Sort 1

 Counting Sort 1
The following is the solution to Hacker Rank problem "Counting Sort 1" using java. For solutions to other Hacker Rank Problem visit my page HackerRank, alternatively try searching for the problem in my blog.

Score: 2/2
/**
 *
 */
package hackerRank;

import java.util.Scanner;

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

       /**
        * @param args
        */
       public static void main(String[] args) {
              // TODO Auto-generated method stub
              Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int numberCount[] = new int[100];
        //track the number count
        for(int i=0;i<n;i++)
        {
            int number = sc.nextInt();
            numberCount[number]+=1;
        }
        //print number count
        for(int i=0;i<numberCount.length;i++)
        {
            System.out.print(numberCount[i]+" ");
        }
       }

}

No comments:

Post a Comment

Labels