Wrie a function which returns the most frequent number in a
list of integers. Handle the case of more than one number
which meets this criterion.
public static int[] GetFrequency(int[] list)

Answer Posted / paras malik

//I strongly feel that this signature is of java instead of
c++ with wrong signature name because function name
according to java conventions should start with small letter.

import java.util.HashMap;
import java.util.Set;

class A{



public static void main(String [] a){


int array[]={1,1,2,1,2,3,4,5,2,3,1};

array = GetFrequency(array);


for(int i =0;i<array.length;i++){

System.out.println(array[i] + "\n");

}

}



public static int[] GetFrequency(int [] array){

HashMap<Integer ,Integer > map = new HashMap<Integer,Integer>();



for(int i =0;i<array.length;i++){


if(map.get(array[i])==null) map.put(array[i],1);
else{
int k = map.get(array[i]);
map.put(array[i],k+1);

}

}

int a[] = new int[map.size()];

Set<Integer> set= map.keySet();
int i =0;
for(int s : set)
a[i++]=map.get(s);
return a;




}

}

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

1+1/2!+1/3!+...+1/n!

1945


How to Split Strings with Regex in Managed C++ Applications?

3136


write a program using 2 D that searches a number and display the number of items 12 inputs values input 15,20, 13, 30, 38, 40,16, 18, 20 ,18 ,20 enter no. to search : 20

3368


write a program to calculate the amount of investment after a period n years if the principal investors was p and interest is calculated using compound interest,formular=a=p(1+r)^n

2373


write a program to convert temperature from fa height into celcius and vise versa,use modular programming

2445






solve the problem in the programming language C++"if a five digit number is input through the keyboard.Write a program to calculate the sum of its digits(hint: use the modulus operator)

2939


Code for Two Classes for Doing Gzip in Memory?

2816


Code for Method of Handling Factorials of Any Size?

2009


What output does this program generate as shown? Why? class A { A() { cout << "A::A()" << endl; } ~A() { cout << "A::~A()" << endl; throw "A::exception"; } }; class B { B() { cout << "B::B()" << endl; throw "B::exception"; } ~B() { cout << "B::~B()"; } }; int main(int, char**) { try { cout << "Entering try...catch block" << endl; A objectA; B objectB; cout << "Exiting try...catch block" << endl; } catch (char* ex) { cout << ex << endl; } return 0; }

586


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.

2071


Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.

4579


We need to write the function to check the password entered is correct or not based on the following conditions.. a) It must have atleast one lower case character and one digit. b)It must not have any Upper case characters and any special characters c) length should be b/w 5-12. d) It should not have any same immediate patterns like abcanan1 : not acceptable coz of an an pattern abc11se: not acceptable, coz of pattern 11 123sd123 : acceptable, as not immediate pattern adfasdsdf : not acceptable, as no digits Aasdfasd12: not acceptable, as have uppercase character

3958


Write a simple encryption program using string function which apply the substitution method.

5543


what mean void creat_object?in public class in this code class A{ public: int x; A(){ cout << endl<< "Constructor A";} ~A(){ cout << endl<< "Destructor A, x is\t"<< x;} }; void create_object(); void main() { A a; a.x=10; { A c; c.x=20; } create_object(); } void create_object() { A b; b.x=30; }

2071


A suduco given & u hv 2 check if it is incomplete(blanks left),or correct or incorrect

2409