Was really a bad/ineffective interview. Spent 1 hour answring and another hour getting grill for each answers. No even introduction, background talk, personality check.
And stress too much on complexity...
(For god sack, I'm not applying for a computer scientist position...)
At the end, the company didn't find out much about me, and I didn't understand more about the company.
Some of the questions.
1. Write a function to reserve the order of words in a string
A fool like donkey --> donkey like fool A
void reverse_str(char *src)
{
char *dst[10]; // note: i must be < 10
char *tmp_word = 0;
char *nextptr;
int i = 0;
tmp_word = strtok_s(src, " ", &nextptr);
while (tmp_word != NULL)
{
dst[i++] = tmp_word;
//printf("%s\n", tmp_word);
tmp_word = strtok_s(NULL, " ", &nextptr);
}
#if 1
for (i=i-1; i >= 0; i--)
{
printf("%s\n", dst[i]);
}
#endif
}
2. Write a function that take int[] arr and output int[] r where r[i] = product of all elements of arr[] exception arr[i]
void function(int[] arr, int[] r, int len)
{
int tmp = arr[0];
for (int i=1; i
{
tmp = tmp * arr[i];
}
for (int i=0; i
{
if (arr[i] = 0)
r[i] = tmp/arr[i];
else
r[i] = 0;
}
}
Original answer was for (i) { for (j) } type.
The interviewer was not happy with the N^2 complexity answer... The above answer should work better.
3. What does not cause a deadlock?
Process ProcA, ProcB
resource a, resource b
Deadlock:
ProcA acquired a, ProcB acquired b
ProcA sem_wait(b), ProcB sem_wait(a)
4. Write a function with (int[] a, int x) to find if x is equal to a summary of any 2 elements in a.
5. Write a function that produce the following output:
1 2 3 4 .... 12
2 4 6 8 .... 24
.
.
.
12 24 36 48 .... 144
6. Write a SQL query to find out the name of student(s) that get highest score in subject name "Math"
student
student_id student_name
subject
subject_id subject_name
grade
student_id subject_id score
Sample database file: link
Can be done this way, but if I answered this during the interview, I would probably asked from "more efficient solution"...
Query1 = SELECT "student_id", "score" FROM "grade" WHERE "subject_id" = ( SELECT "subject"."subject_id" FROM "subject" WHERE "subject"."subject_name" = 'Math' )
Query2 = SELECT "student_id" FROM "Query1" WHERE "score" = ( SELECT MAX( "score" ) FROM "Query1" )
Query3 = SELECT "student_name" FROM "student" WHERE "student_id" IN ( SELECT "Query2"."student_id" FROM "Query2" )
Another approach:
Query1 =
Query2 = SELECT student.student_name, subject.subject_name, grade.score FROM student, subject, grade WHERE student.student_id=grade.student_id AND subject.subject_id=grade.subject_id
7. What data structure is best for mapping of NRIC to Name?
Memory crashed... Forget some questions
11. Have a singly link-list, given a pointer to a random element in the link-list.
Use diagram to describe how to delete the element.
Correct answer:
(HEAD)--->()--->()--->(x)--->()--->null
x contains { data, *next }
tmp = x->next (copy the data and *next of x->next)
delete x->next
12. Find mistakes in 3 programs
(a)
class Rational {
private:
int a, b;
friend Rational& operator*(const Rational& lh, const Rational& rh);
}
inline Rational& operator*(const Rational& lh, const Rational& rh)
{
Rational result(lh.a * rh.a, lh.b * rh.b);
return result;
}
-> Correct should be Rational operator*(...)
result is local in operator*, returning reference is invalid.
(b)
Something to do with virtual bool destroy()
class Base {
virtual bool destroy();
private:
static size_t numOfBase;
}
class Derived: public Base
{
....
}
I think the mistake is Drived didn't implement destroy().
(c)
Some function that copy the domain part of the fqdn, if the . is not found, append the default_domain to it.
abc@ibm.com --> return string as ibm.com
abc@encentuate (default_domain = .ibm.com) --> return string as encenture.ibm.com
char* function(char* fqdn, char *default_domain)
{
....
basic checking
get the string after '@'
allocate mem for result
if (size checking failed)
{
return NULL; // here memory allocated was not freed.
}
if (result contains not '.')
strcat(result, default_domain); // here the reminding space of result might not fit default_domain)
...
}
No comments:
Post a Comment