JOIN
Get Time
forums  Revision History
Search My Post History  |  My Watches  |  User Settings
Forums Round Tables General Career Discussions Re: Meh? Revision History (2 edits)
Re: Meh? (response to post by jmzero)
"edit-as-you-pass-through" clever solution (which I think is horrible - negligible performance benefit over d000hg's approach, and painful to work with)

Can you elaborate on that? I don't see either why it is faster or why it is painful to work with. I have no trouble working with unique in C++ and that's how it is implemented. The reason is that it generalizes for arbitrary large alphabets. Also, I wouldn't mind maintaining the following.
// requires that s is a sorted null terminated string
// ensures that repeated letters in s are removed
// returns a pointer to the new end of the string
// ensures *result == 0
char* unique(char* s) {
  // s points to the last saved character
  // t points to the character currently examined
  char* t = s;
  do {
    if (*++t != *s) *++s = *t;
  } while (*t);
  return s;
}
I agree with you that the question is horrible. I would be very suspicious if an interviewer asks me to write a function that returns something and the signature has void for the return type. I would be even more suspicious in I'm working with C strings and there is an extra length parameter. I was also about to write a message asking what's wrong with d000hg's solution. (BTW, d000hg, your handle is horrible. It took me more time to spell it correctly than to write the rest of the message :) )

PS: In fact, I would prefer to use a smarter language that allows me to write at least the method contract comment in a way understood by tools. (for example Spec#, Java+JML, Eiffel)
Re: Meh? (response to post by jmzero)
"edit-as-you-pass-through" clever solution (which I think is horrible - negligible performance benefit over d000hg's approach, and painful to work with)

Can you elaborate on that? I don't see either why it is faster or why it is painful to work with. I have no trouble working with unique in C++ and that's how it is implemented. The reason is that it generalizes for arbitrary large alphabets. Also, I wouldn't mind maintaining the following.
// requires that s is a sorted null terminated string
// ensures that repeated letters in s are removed
void unique(char* s) {
  // s points to the last saved character
  // t points to the character currently examined
  char* t = s;
  do {
    if (*++t != *s) *++s = *t;
  } while (*t);
}
I agree with you that the question is horrible. I would be very suspicious if an interviewer asks me to write a function that returns something and the signature has void for the return type. I would be even more suspicious in I'm working with C strings and there is an extra length parameter. I was also about to write a message asking what's wrong with d000hg's solution. (BTW, d000hg, your handle is horrible. It took me more time to spell it correctly than to write the rest of the message :) )

PS: In fact, I would prefer to use a smarter language that allows me to write at least the method contract comment in a way understood by tools. (for example Spec#, Java+JML, Eiffel)
Re: Meh? (response to post by jmzero)
"edit-as-you-pass-through" clever solution (which I think is horrible - negligible performance benefit over d000hg's approach, and painful to work with)

Can you elaborate on that? I don't see either why it is faster or why it is painful to work with. I have no trouble working with unique in C++ and that's how it is implemented. The reason is that it generalizes for arbitrary large alphabets. Also, I wouldn't mind maintaining the following.
// requires that s is a sorted null terminated string
// ensures that repeated letters in s are removed
void unique(char* s) {
  // s points to the last saved character
  // t points to the character currently examined
  char* t = s;
  do {
    if (*++t != *s) *++s= *t;
  } while (*t);
}
I agree with you that the question is horrible. I would be very suspicious if an interviewer asks me to write a function that returns something and the signature has void for the return type. I would be even more suspicious in I'm working with C strings and there is an extra length parameter. I was also about to write a message asking what's wrong with d000hg's solution. (BTW, d000hg, your handle is horrible. It took me more time to spell it correctly than to write the rest of the message :) )

PS: In fact, I would prefer to use a smarter language that allows me to write at least the method contract comment in a way understood by tools. (for example Spec#, Java+JML, Eiffel)