Amazon Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

Does this mean deleting every instance of a particular substring from the source string?

- Ravi August 26, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can anyone shed more light on the algorithm for this problem?

- arvo October 29, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

http://www.google.com/codesearch for strtok.

- Khoa October 29, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/* strtok example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str[] ="- This, a sample string.";
  char * pch;
  printf ("Splitting string \"%s\" into tokens:\n",str);
  pch = strtok (str," ,.-");
  while (pch != NULL)
  {
    printf ("%s\n",pch);
    pch = strtok (NULL, " ,.-");
  }
  return 0;
}

Output:

Splitting string "- This, a sample string." into tokens:
This
a
sample
string

- zdmytriv January 29, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is a sample code:
{static char *ts = NIL; /* string to locate tokens */

char *strtok (char *s,char *ct)
{
char *t;
if (!s) s = ts; /* use previous token if none specified */
if (!(s && *s)) return NIL; /* no tokens */
/* find any leading delimiters */
do for (t = ct, ts = NIL; *t; t++) if (*t == *s) {
if (*(ts = ++s)) break; /* yes, restart seach if more in string */
return ts = NIL; /* else no more tokens */
} while (ts); /* continue until no more leading delimiters */
/* can we find a new delimiter? */
for (ts = s; *ts; ts++) for (t = ct; *t; t++) if (*t == *ts) {
*ts++ = '\0'; /* yes, tie off token at that point */
return s; /* return our token */
}
ts = NIL; /* no more tokens */
return s; /* return final token */
}}

- Anonymous February 19, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You can also break each and every word of the string (including spaces) and put in a linked list...eg:
String: "Please tokenize this string"
So the LL will be:
HEAD--->"Please"--->" "--->"tokenize"---->" "---->"this"---->"string"--->NULL

- Anonymous March 19, 2008 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More