You are not logged in. Please login at www.codechef.com to post your questions!

×

RTE in "Count of Maximum"

import java.io.*;
class counting
{
    public static void main (String args[])throws IOException
    {
      BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
      int t=Integer.parseInt(in.readLine());
      while(t-->0)
      {
        int n=Integer.parseInt(in.readLine());
        String s=in.readLine();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
        {
        a[i]=Integer.parseInt(s.split(" ")[i]);
        }
        int b[]=new int[100];
        for(int i=0;i<100;i++)
         b[i]=0;

        int y=0,max=0;
            for(int j=0;j<n;j++)
            {
            b[a[j]-0]++;
            }

                for(int i=0;i<=100;i++)
                {
                 if(max<b[i])
                 {
                   max=b[i];
                   y=i;
                 }
                }

          System.out.println(y+" "+max);

      }
    }
}

asked 14 Nov '14, 01:12

ashish9aayu92's gravatar image

2★ashish9aayu92
1
accept rate: 0%

converted to question 14 Nov '14, 02:28

betlista's gravatar image

3★betlista ♦♦
16.9k49115225


length of array b is 100 and your last loop is from i=0 to i<=100 . Array b can have only indices from 0 to 99

link

answered 14 Nov '14, 01:50

h9k6's gravatar image

3★h9k6
54115
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×55
×26

question asked: 14 Nov '14, 01:12

question was seen: 538 times

last updated: 14 Nov '14, 02:29