
В принципе это пожалуй самые простые вопросы, которые мне когда-то задавали, но всё же... Прокоментируйти покритикуйти.


Hi VG,
Thank you for your application. We take great care to pick
the very best talent we can find within Canada. We put a lot of
effort into helping developers build up their potential and skills.
Our recruitment process begins with a few standard pre-screening questions
that give you the opportunity to demonstrate your ability.
1) Are you a permanent resident or citizen of Canada? Unfortunately
we must give precedence to candidates with citizenship to comply with
CCRA regulations.
*** A:
Yeas I am. I am a permanent resident, landed immigrant.
2) Please write the code to implement the following C function:
void ReverseString(char* pString);
The argument should be a null terminated string which should be
reversed. i.e. if Hello\0 is passed in it comes out as olleH\0.
***A:
Here I did not use the well known algorithms working without temporary variables. The reason is that the algorithm below will work with TCHAR also:
void ReverseString(char* pString)
{
if ( !pString ) return;
int endIndex = 0;
while ( pString[ endIndex ] != '\0' ) endIndex ++;
if ( ! endIndex ) return;
endIndex --;
char tmp;
for ( int startIndex = 0; startIndex < endIndex; startIndex ++, endIndex-- )
{
tmp = pString [startIndex];
pString [startIndex] = pString[endIndex];
pString [endIndex] = tmp;
}
}
3) Given a singly forward linked list i.e.
A->B->C->D
describe the algorithm that could efficiently reverse the order
of the list:
D->C->B->A
***A:
I did not want copying the code from some of the Cisco interview samples questions. Have a look at http://www.techinterviews.com/index.php?p=20 question and answer for instance. That is why here is my own algorithm which I did for you in a dozen of minutes. Have a look at the ReverseList recursive function. It could be better thanks to the lower number of loops and “ifs” here.
typedef struct tagNode
{
// int val;
tagNode* next;
} t_Node, * PNode;
void _reverse2nodes( PNode head )
{
if ( !head->next) return;
PNode curnext = head->next->next;
head->next->next = head;
if ( curnext )
{
_reverse2nodes( curnext );
curnext->next = head->next;
}
}
void ReverseList( PNode head )
{
if ( !head ) return;
_reverse2nodes( head );
head->next = 0L;
}
///////////////////
Usage:
t_Node A, B, C, D;
A.val = 0;
A.next = &B;
B.val = 1;
B.next = &C;
C.val = 2;
C.next = &D;
D.val = 3;
D.next = 0L;
ReverseList( &A );
4) Please write the code required to count the number of bits set
in a byte. The function should have the prototype:
int Count(unsigned char Byte);
***A:
Here is the function:
int Count(unsigned char _Byte)
{
int rc = 0;
for (int i = 7; i > 0; i--) rc += ( _Byte >> i ) & 0x1 ;
return ( rc += _Byte & 0x1) ;
}
If you are able to demonstrate you ability in these questions and have
Canadian citizenship or residency we can move to the next step of a phone
interview.