Monday 21 July 2014

Technical interview quest day 1

Finally I stopped myself from googling/ reading article about technical interview and start focusing on the coding practice. Today the topic I did are:
  1. Array, dynamic array (yup, I am reinforcing my basic data structure and algorithm daily)
  2. Describe C++ casting
  3. Which one is faster: while(1) or while(2)
  4. Programming question:  write a function that put a C string without looping constructs or using local variables. Then implement a reverse string function the same manner as the first one.
  5. Programming question: write a function that reverse a string (similar to above but instead of printing the string inside the function, we want the function to return the reverse of the input string).
  6. Programming question: write a function that reverse a sentence.
  7. Programming question: write a function to compute nth fibonacci number.
  8. Programming question: print out the grade-school multiplication table up to 12x12
Answers: (PS: please feel free to correct me if I am wrong)
  1. This has a good coverage: http://en.wikipedia.org/wiki/Array_data_structure.
  2. Static cast, const cast, reinterpret cast, dynamic cast. These two articles have good explanation about it: http://stackoverflow.com/questions/28002/regular-cast-vs-static-cast-vs-dynamic-cast and http://stackoverflow.com/questions/332030/when-should-static-cast-dynamic-cast-const-cast-and-reinterpret-cast-be-used.
  3. Depends on the compiler. While some compiler may optimize both to the same while(true), some is not. In C, for example, there is no boolean type. C will treat it as integer thus comparing integer 0 with 1 or 2 doesn't make any differences. In C++, however, bool type is defined as either true (1) or false (0). Upon seeing while(2), C++ will cast it first to bool which takes another cycle. Thus while(2) will take longer time than while(1).

No comments:

Post a Comment