Microsoft Interview Question for Software Engineer / Developers






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

www dot testskillshome dot com/?p=2286

- Mister March 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

there it is mentioned tht it has to be done in logn but how u have to parse thru the string completly which takes 'n'

- sriks March 17, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

/*
 * tokenize() is based on strsep()
 * The only difference is how they handle the empty fields.
 */

bool match(char *c, const char *delim)
{
  unsigned int len = strlen(delim);
  for (unsigned int i = 0; i < len; i++) {
    if (*c == *(delim + i))
      return true;
  }
  return false;
}
char *tokenize(char **stringp, const char *delim)
{
  char *p = *stringp;
  // If *stringp is initially NULL, strsep() returns NULL.
  if (*stringp == NULL)
    return NULL;
  unsigned int len = strlen(*stringp);
  for (unsigned int i = 0; i < len; i++) {
    /*
     * locates, in the string referenced by *stringp, the
     * first occurrence of any character in the string delim
     * and replaces it with a '\0'
     */
    if (match(p + i, delim)) {
      *(p + i) = '\0';
      for (unsigned int j = 1; j < len - i - 1; j++) {
        /*
         * The location of the next non-delimiter character after
         * the delimiter character (or NULL, if the end of the
         * string was reached) is stored in *stringp.
         */
        if (!match(p + i + j, delim)) {
          *stringp = (p + i + j);
          break;
        }
      }
      break;
    }
  }
  if (*stringp == p)
    *stringp = NULL;
  // The original value of *stringp is returned.
  return p;
}
int main()
{
  char *token, *string, *tofree;
  tofree = string = strdup("abc def ,ghi");
  assert(string != NULL);
  while ((token = tokenize(&string, " ,")) != NULL) {
    printf("%s\n", token);
  }
  free(tofree);
}

- leeym March 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Treat String as a character array

2. Use a finite state machine while int nextChar is less than the string length and a temporary character array of a set size to hold the current token.

3. in the finite state machine: while(string[nextChar] != ' ') { nextToken[nextTokenChar++] = string[nextChar++] }

4. When the nextChar does equal ' ' , place null terminator on nextToken buffer and add it to a linked list of tokens and then increment the nextChar until string[nextChar] != ' ' (thus eliminating the worry about repeating white spaces.

- Nick March 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="" line="1" title="CodeMonkey48883" class="run-this">/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;

/**
*
* @author USE
*/
public class StringToken {

public String[] splitStrings(char[] c) {

StringBuffer sb = new StringBuffer();
int index = 0;
String[] str = new String[10];
if (c.length == 0) {
return null;
}

for (int i = 0; i < c.length; i++) {

if (c[i] == ' ')

if (c[i+1] == c[i]) { //multiple blank spaces
continue;
} else { //single blank space

// allocate the created stringbuffer to newly created string and
//increment the index

str[index] = new String(); // create a new string
str[index] = sb.toString();
sb = new StringBuffer();
index++;

}
else {
sb.append(c[i]);
}
str[index]= sb.toString();




} //end of for loop

return str ;
}
public void validateToString(){
char [] x = new char[]{'T','h','i','s',' ',' ','i','s',' ',' ',' ',' ','L','A','L','I','T'};
String [] str = splitStrings(x);

for(int i=0;i<str.length;i++){
if(str[i]!=null)System.out.println(str[i]);
}

}

public static void main(String agrs[]){

new StringToken().validateToString();
}
}
</pre><pre title="CodeMonkey48883" input="yes">
</pre>

- Anonymous August 05, 2011 | 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