Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

#include <stdio.h>
#include <string.h>
void main()
{
    char * string = "darks. knoght, rises";
    int size = strlen(string);
    int i=0, word_counter=0;

    while (i < size)
    {
        if (string[i] == ' ')
        {
            printf("%i ", word_counter);
            word_counter = 0;
            i++;
            continue;
        }
        word_counter++;
        i++;
    }
    if (word_counter)
    {
        printf("%i ", word_counter);
    }
}

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

In java, it can be done simply by using tokenize function with separator as whitespace.

- Learner July 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Obviously no in built functions allowed!

- sylarific July 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

//c code for this

#include<stdio.h>
#include<string.h>
main()
{
char* st="the dark night";
char str1[40]="";
char temp[4];
int i,len=strlen(st),count=0;
for(i=0;i<len;i++)
{
if(st[i]==' ')
{
itoa(count,temp,10);
strcat(str1,temp);
count=0;
}
else
{
count++;
}
}
itoa(count,temp,10);
strcat(str1,temp);
printf("%s",str1);
return 0;
}

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

# Ruby code

str = "career cup."
str_length = str.length
result = {}
start_chr_pos = curr_chr_pos = 0
while curr_chr_pos < str_length + 1 do
if str[curr_chr_pos] === " " || curr_chr_pos == str_length
result[str[start_chr_pos..curr_chr_pos-1]] = curr_chr_pos - start_chr_pos
start_chr_pos = curr_chr_pos + 1
end
curr_chr_pos += 1
end

puts result
>> {"career"=>6, "cup."=>4}

# ========== Very short form
# puts str.split(" ").inject(Hash.new { |h,k| h[k] = []}) { |h,s| h[s] << s.length; h}

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

http://jsfiddle.net/abhimehta/THj8r/

var s = "career cup.";
var count = 1;
for(i=0; i<s.length; i++)
{
    if(s[i] == " ")
    {
        document.write((count-1)+"<br/>");
        count = 0;                    
    }
    else if( i == s.length-1 )
        document.write(count);
    
    count++;
}​

- am15851 July 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

just to modify a bit on your code, since we need to return a string, may be this works:

<!DOCTYPE html>
<html>
<body>

<p id="demo">Click the button to convert the array into a String.</p>

<button onclick="myFunction()">Try it</button>

<script type="text/javascript">
function myFunction()
{
//var s = "career cup.";
var s= "Dark, Knight, Rises!";
var ans=[];

var count = 1;
for(i=0; i<s.length; i++)
{
if(s[i] == " ")
{
// document.write((count-1)+"<br/>");
ans.push(count-1);

count = 0;

}
else if( i == s.length-1 )
{ ans.push(count);

}
// document.write(count);

count++;
}
ans.toString();
//document.write(ans);
var x=document.getElementById("demo");
x.innerHTML=ans;
}
</script>

</body>
</html>

- sylarific July 22, 2012 | Flag


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