Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


A string of charaters were given. Find the highest
occurance of a character and display that character.
eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE

Answers were Sorted based on User's Feedback



A string of charaters were given. Find the highest occurance of a character and display that chara..

Answer / paindriven

char HighestCharCount(const char* str)
{

const int length = strlen(str);
if (length == 0)
return ' ';
if (length == 1)
return str[0];

int indexOfHighest = int(-1);
int highestCounter = 0;
for (int i=0; i < length; ++i)
{
const int remain = length - i;
char test = str[i];
int current = 0;
for (int j=i+1; j < remain; ++j)
{
if (str[j] == test)
{
current++;
if (current > highestCounter)
{
highestCounter = current;
indexOfHighest = i;
}
}
}
}
return str[indexOfHighest];
}

Is This Answer Correct ?    38 Yes 10 No

A string of charaters were given. Find the highest occurance of a character and display that chara..

Answer / aman bhullar

#include<string.h>
#include<stdio.h>


char HighestCharCount(char* str)
{

int length = strlen(str);
if (length == 0)
return ' ';
if (length == 1)
return str[0];

int indexOfHighest = -1;
int highestCounter = 0;
int i, j ,current = 0;
char test;
for ( i=0; i < length; ++i)
{
test = str[i];

for (j=i+1; j < length ; ++j)
{
if (str[j] == test)
{
current++;
}

if (current > highestCounter)
{
highestCounter = current;
indexOfHighest = i;
}
}
}
return str[indexOfHighest];
}

void main ( )
{
char a[] = "AEGBCNAvNEETGUPTAEDAGPE";
char res;
res = HighestCharCount(a);
printf("\n %c ", res);

}

Is This Answer Correct ?    9 Yes 1 No

A string of charaters were given. Find the highest occurance of a character and display that chara..

Answer / aman

Answer 2 is giving output A instead of E

Is This Answer Correct ?    5 Yes 1 No

A string of charaters were given. Find the highest occurance of a character and display that chara..

Answer / rohit tehlan

using System;
using System.Linq;

namespace StringHighestCharacterOccur
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the character string ");
string str = Console.ReadLine();

int[] max = new int[str.Length]; // this will store occurence count for each character
for (int i = 0; i < str.Length; i++)
{
int count = 0;
for (int j = 0; j < str.Length; j++)
{
if (str[i] == str[j])
{
count++;
}
}
max[i] = count;
}
int maxvalue = max.Max();
int maxvalueindex = max.ToList().IndexOf(maxvalue); // this will give the index of character with max occurence
Console.WriteLine("Character with max occurence is: " + str[maxvalueindex]);
Console.ReadLine();
}
}
}

Is This Answer Correct ?    3 Yes 0 No

A string of charaters were given. Find the highest occurance of a character and display that chara..

Answer / upinder

to find the answer
visit..
http://advance-programing.blogspot.com/2010/01/string-of-charater-is-givenfind-highest.html

Is This Answer Correct ?    3 Yes 1 No

A string of charaters were given. Find the highest occurance of a character and display that chara..

Answer / arpita

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

public class TestClass1 {
public static void main(String[] args) {
HashMap<Character, Integer> hm = new HashMap<Character,
Integer>();
String str = "AABBBCCZX";
if (str != null) {
char[] charArray = str.toCharArray();
for (char ch : charArray) {
int counter = 0;
for (int j = 0; j < charArray.length; j++) {
if (ch == charArray[j]) {
counter = counter + 1;
}
}
hm.put(ch, counter);
}

Set<Character> s = hm.keySet();
Iterator<Character> itr = s.iterator();
while (itr.hasNext()) {
char key = (char) itr.next();
System.out.println("Character : " + key + " Occurence : "
+ hm.get(key));
}
}

}
}

Is This Answer Correct ?    3 Yes 1 No

A string of charaters were given. Find the highest occurance of a character and display that chara..

Answer / guest

using System;
static void main()
{
string a=AEGBCNAvNEETGUPTAEDAGPE;

Is This Answer Correct ?    2 Yes 29 No

Post New Answer

More Programming Languages AllOther Interview Questions

For a binary tree with n nodes, How many nodes are there which has got both a parent and a child?

0 Answers  


How to change the color of a cell or a row in a datagrid on mouse hover using javascript/.net

0 Answers   Tesco, Wipro,


How to print No.of.rows affected after updation using ADO.Net

0 Answers   Tech Mahindra,


How can we alter the data after creating a view

1 Answers  


what is web service in java? have u use before.

0 Answers  


hi all, i need ur help in preparing a sql which performs scd2, i mean i have a scd2 mapping i need a sql which can give me same result as scd2 mapping, SRC table: cust_no, loc 01 abc 02 xyz TGT table: pm_ky cust_no loc current_flag 1 01 abc Y 2 02 xyz Y cust 1 has changed his loc to xyz then it loads into TGT table as below, pm_ky cust_no loc current_flag 1 01 abc N 2 02 xyz Y 3 01 xyz Y i need sql to get the above result, hope got me question, Any suggestion will be appreciate.. thanks, Vinod

0 Answers  


A combination of multiple keys defined in a physical file or logical file is called a _________ key

3 Answers   IBM,


73. How can you set the status and title for a modal dialog box? a) In the attributes of the corresponding screen. b) Before the corresp. call screen statement. c) In a PBO module of the corresponding screen. d) In the PAI module of the corresponding screen.

1 Answers  


what is the certificates in biztalk?

0 Answers  


what is session state?

0 Answers   HCL,


what is lazy loading in hibernate?Explain in detailed manner?

2 Answers   IBM, TCS,


HTML is a subset of

8 Answers  


Categories