Labs247 Interview Question for Quality Assurance Engineers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
2
of 2 vote

public static void occuranceWord(String string, String word){
String original = string;
int count =0;

String[] str2 = original.split(" ");
int l = str2.length;

String str3=null;

for(int i=0; i<l; i++){

if(word.equals(str2[i])){
++count;
}

}
System.out.println(count);

}

- naveengarg2k5 July 23, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

#include <iostream>
#include <string>
#include <map>
using namespace std;

void countWordsInString(string a)
{
	if(a.empty())return;
	int low = 0;
	int high = 0;
	map<string, int> countCenter;
	while(a[low] != '\0' && a[low] == ' ')
	{
		low++;
		high = low;
	}
	while(high < (int)a.size())
	{
		while(a[high] != ' ' && a[high] != '\0')
			high++;
		countCenter[a.substr(low, high - low)]++;
		while(a[high] == ' ')
			high++;
		low = high;
	}

	for(map<string, int>::iterator i = countCenter.begin(); i != countCenter.end(); i++)
	{
		cout<<i->first<<":"<<i->second<<endl;
	}
}

int main()
{
	string a = "Hello I am going to I with Hello am";
	countWordsInString(a);
}

- ming June 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

use map

- rashmi sampath June 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As the questions speaks about finding the count of a particular word.
So, a buffer can be maintained for each word & matched with the word to be searched.

An alternate way is to use TRIE & at the leaf nodes, count the number of occurrences. If words are to be outputted in sequence with the sentence, search for each word in the TRIE else do an inorder traversal.

- Aashish June 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*  find the no. of time a particular word is occurring in a string?
eg. "Hello I am going to I with Hello am"?  */

//         WORKING CODE

#include<stdio.h>
#include<string.h>
int main()
{
    char S[50],W[20][10],C[20];
    int i=0,j,l,k=0,A[20]={0},flage=0;
    gets(S);
    l=strlen(S);
    W[0][0]='\0';
    while(i<l)
    {
        j=0;
        flage=0;
        for(;S[i]!=' ' && i<l;i++)
            C[j++]=S[i];
        C[j]=NULL;
        for(j=1;j<=k;j++)
            if(!strcasecmp(C,W[j]))  // strcasecmp() return 0 on equal
            {
                A[j]++;
                flage=1;
                break;
            }
        if(!flage)
        {
            k++;
            strcpy(W[k],C);
            A[k]++;
        }
    i++;
    }// end of while
    printf("\n");
    for(i=1;i<=k;i++)
        printf("\n%d\t%s",A[i],W[i]);
    printf("\n");
return 0;
}

- niraj.nijju June 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
String word="Hello I am going to I with Hello am";

HashMap<String,Integer>map=new HashMap<String,Integer>();
String []words=word.split(" ");

for(String wor:words){
if(map.containsKey(wor)){
int count=map.get(wor);
count=count+1;
map.put(wor, count);
}
else{
map.put(wor, 1);
}
}
System.out.println(map);
}
}

- Anonymous July 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int countOccurance(String input, String word, int count) {
		if (input == null || word == null || input.isEmpty() || word.isEmpty())
			return 0;

		if (input.length() < word.length())
			return count;

		String subString = input.substring(0, word.length());
		if (subString.equals(word))
			return countOccurance(input.substring(word.length()), word, count + 1);
		else
			return countOccurance(input.substring(1), word, count);
	}

- Pawan Mittal July 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// Find the number of occurrences of a particular word.
	public static int countOccurance(String input, String word, int count) {
		if (input == null || word == null || input.isEmpty() || word.isEmpty())
			return count;

		if (input.length() < word.length())
			return count;

		String subString = input.substring(0, word.length());
		if (subString.equals(word))
			return countOccurance(input.substring(word.length()), word, count + 1);
		else
			return countOccurance(input.substring(1), word, count);
	}

- pamit July 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In java it can be done like this:	

	String str ="Hello I am going to I with Hello am";
		String[] arr_str = str.split(" ");
		int len =arr_str.length;
		
		//sort the string
		for(int i=0; i<len; i++)
		{
			for(int j=1; j<(len-i); j++)
			{
				if(arr_str[j-1].compareToIgnoreCase(arr_str[j])>0)
				{
					String temp = arr_str[j-1];
					arr_str[j-1]=arr_str[j];
					arr_str[j]=temp;
				}
			}
		}

		//now count the number of times the words are repeated
		try{
		for(int a=0; a<len; a++)
		{
			int count =1;
			if(arr_str[a].equals(arr_str[a+1]))
			{
				count++;
				System.out.println(arr_str[a]+" is repeated "+count+" times" );
				
			}
		}
		}
		catch(Exception e){}
			
		
		}

- puja July 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String args[]){
String sat = "Hello I am going to I with Hello am";
String[] s = sat.split(" ");

for(int i=0;i<s.length;i++){
int count = 0;
for(int j=0;j<s.length;j++){
if(s[i].equals(s[j])){
count = count+1;
// System.out.print(s[j] + " ");
}
}
System.out.println(s[i]+" "+count);
}
}

- sathishwaran February 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

ublic class NumberOfOccurringWord {
public static void main(String args[]){
String name = "hello i am going to hello";
String word = "hello";
int i;
int count = 0;
String arr[] = name.split(" ");
for(i=0 ;i<arr.length;i++){
if(word.equals(arr[i])){
++count;
}
}
System.out.print(count);
}

- napendra@canbrand.in July 04, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More