This is a test I did for a role of junior developer that a company was recruiting for.
It is just a small little problem and they gave us I think 15 or 20 minutes. Really, it is quite simple unless you haven't manipulated strings in a while :O, then it might take a little longer to do, but it'll be done.
THE PROBLEM:
Given a string S, such as "We are coders. Forget CVs !" the aim is to break it down into sentences, like in the example would be "We are coders" and "Forget CVs ". the '.', '?' and '!' are delimiters, so we need to break the string into a sentence when only one of those three characters occur.
Each sentence can be formed by 1 or more words, or it can be an empty sentence. So sentence "We are coders" would be formed by 4 blocks (3 words and empty sentence).
" Forget CVs " is formed by 2 words and empty sentence =3.
The aim is to compute what is the maximum number of blocks given a string S. In this case it would be 4.
In the example "The mountain is tall. I rather be in the beach? Oh la la !". The would be three sentences: "The mountain is tall"(5 blocks), "I rather be in the beach?"(7 blocks) and "Oh la la "(4 blocks). The return answer would be 7.
QUICK SOLUTION:
public static int Blocks (string S)
{
char [] sentenceDelimiters = {'.', '?', '!'};
int result =0;
string [] sentences= S.Split(sentenceDelimiters);
for (int i=0; i<sentences.Length; i++)
{
int countWords;
sentences[i]= sentences[i].Trim(); // eliminates any start/end white space
if (String.IsNullOrEmpty(sentences[i])) countWords =1; // test says an empty sentence counts as 1.
else countWords = sentences[i].Split().Length +1; // add 1 to count an empty sentence.
if (countWords > result) result = countWords;
}
return result;
}
To refresh knowledge about class String and its methods:
It wasn't hard, but junior developer tests are like a lotto, you never know what topic out of a zillion you might get!
PR
Small tests used by various companies to pre select candidates applying for a role (junior role). Brainteasers and others. Solutions in c#.
Showing posts with label interview. Show all posts
Showing posts with label interview. Show all posts
Thursday, 25 June 2015
Monday, 22 June 2015
JUNIOR C# DEVELOPER TEST QUESTIONS
From the various online tests sent to me while applying to junior c# developer positions I have chosen a few theoretical questions. Because yes, they also ask theory?!!
- How many clustered indexes can be created on single table?
- In SOLID principle, what "I" stands for.
- Dependency injection implements Inversion of control principle. (True or False)
- WCF does not support service oriented architecture that's why Web API was introduced. (True or False)
- Difference between struct vs classes.
- What is an interface?
- What is StringBuilder?
- ABC of endpoint, C refers to what is exposed by the service. (True or False)
- Which protocol is used by REST web services.
- In your opinion what are the two main differences between WCF and Web API services?
- Can a private virtual method be overridden?
- Value types.
- What means virtual?
- What is inheritance? (I've never had a test interview where they don't ask this one :p)
- What means the keyword out?
- What means static?
- Can multiple catch blocks be executed? (True or False)
- What access modifier we use to restrict a class being inherited?A) StaticB) VoidC) SealedD) We can't restrict a class being inherited.
Subscribe to:
Posts (Atom)