HCL Interview Question for Developer Program Engineers


Team: 8
Country: India
Interview Type: In-Person




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

the example is wrong, the e from mouse should not be output, instead the 3rd N from running fits the pattern.

{
string inString = "Once when a Lion was asleep, a little Mouse began running up and down upon him. ";
string[] Words = inString.Split(new char[] { ' ', '.', ',', '!', '?' }, StringSplitOptions.RemoveEmptyEntries);

int EndPos = Words.Length;
int CurPnt = 1;

string WordOut = string.Empty;
for (int i = 0; i < EndPos; i++)
{
string parseword = Words[i];

if (CurPnt > parseword.Length)
{
if (WordOut.Length > 0)
{
Console.WriteLine(WordOut);
WordOut = string.Empty;
}
}
else
{
WordOut = WordOut + parseword[CurPnt - 1] + " ";
CurPnt++;
}
}
if (WordOut.Length > 0)
{
Console.WriteLine(WordOut);
WordOut = string.Empty;
}
string Oprkeys = Console.ReadKey().ToString();
}
}

- Woody November 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i think this is not a c++ code

- Gomathi January 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main(int argc,WCHAR *argv[])
{
	string paraGrp = "Once when a Lion was asleep, a little        Mouse began running up and down upon himxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxx.";

	/*stringstream ss(paraGrp);
	string buffer;	
	int count =0;
	while(ss >> buffer)
	{
		
		if(buffer.length() > count)
			printf("%c",buffer[count]);
		else
			printf("\n");
		count++;
	}*/
	char delim= ' ';
	int lastPrint=0;
	int spaceCount=0;
	for(int i=0;i< paraGrp.length();i++)
	{
		if(paraGrp[i] == delim && paraGrp[i+1] == delim)
			continue;
		if(paraGrp[i] == delim)
		{
			if(i - lastPrint < spaceCount+1)
			{
				printf("\n");
				spaceCount++;
				lastPrint = i+1;
			}
			else if (lastPrint+spaceCount <paraGrp.length())
			{
				printf("%c",paraGrp[lastPrint+spaceCount]);
				spaceCount++;
				lastPrint = i+1;
			}			
		}
		
	}
	printf(" SpaceCount %d , lastPrint %d ",spaceCount,lastPrint);

}

- Prakash January 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#define MBUF    1024
int main()
{
    char buff[MBUF] = {0,};
    int n = 0;

    while(fgets( buff, MBUF, stdin ) )
    {
        n = strlen(buff);
        if( buff[n-1] == '\n' )
        {
            buff[n-1] = '\0';
            n--;
        }

        char *bptr = NULL, *token = NULL, *sptr = NULL;
        int count = 0;

        for ( bptr = buff ;; bptr = NULL )
        {
            token = strtok_r( bptr, " ", &sptr );
            if( token == NULL )
                break;

            if( strlen(token) < count )
                printf("\n");
            else
                printf("%c", token[count]);

            count++;
        }

    }
}

- Anonymous March 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
int main()
{
char a[50];
printf("enter the string:");
gets(a);
printnchar(a);
}

void printnchar(char *p)
{
char *s;
int i=0,c=0;
while(*p!='\0')
{
c=0;
s=p;
while((*s!=' ')&&(*s!='\0'))
{
c++;
s++;
}

if(c>i)
{
printf("%c",*(p+i));
i++;
}
else
{
printf("\n");
}
if(*s!='\0')
{
p=s+1;
}
else
{
p=s;
}
}

- Basha May 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think the example output is wrong if the question is right. Taking the question as right into consideration the output should be something like
Oh
o
e
l

n


.

Thus the solution in will be :
#include<stdio.h>
#include<string.h>
#include<iostream>

using namespace std;
#define DELIM_SPACE " "
main()
{
char* curr_str, *saveptr, msg_data[200] = "Once when a Lion was asleep, a little mouse began running up and down upon him";
into i = 0;
while(NULL != (curr_str = strtok_r(msg_data, DELIM_SPACE, &saveptr))) {
int l = strlen(curr_str);
(i < l && l> 3) ? std :: court << curr_str[i++] : std:: cout << " \n";
strcpy(msg_data, saveptr);
}

}

- burmanvishal September 09, 2014 | 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