News for hackers. Stuff that matters.
Re:Interviewing programmers: coding test example explained by philwelch on Thursday June 03, 2010 @07:04PM (#1402908)
You can use an inner loop to skip over removable chars in the source string but I didn't think that was n^2. (Code below for reference.) Am I wrong that my solution is n, or is there another obvious n^2 algorithm?

  void condense_by_removing( char *z_terminated , char char_to_remove)
  {
    char * sp;
    char * dp;
    sp = dp = z_terminated;
    while (*sp != '\0') {
      while (*sp == char_to_remove){
        sp++;
      }
      *dp = *sp;
      dp++;
      sp++;
    } 
    *dp = *sp;
  }

There are no comments on this comment yet.