Microsoft Interview Question for Software Developers


Team: Bing
Country: United Kingdom
Interview Type: Written Test




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

I have few question what about CC? BCC? why where those skipped? does the substring be unique characters?

- Gear March 05, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

The substrings should be composed of strictly increasing characters, so BCC is not valid

- sergio March 05, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Given String consider as s;

String s;
list<string> output;
for(int i=0;i<s.length;i++)
{
int k=i;
for (int j=i+1;j<s.length;j++)
{
if(s[k]<s[j])
{
output.add(s.substring(i,j-i+1));
k=j;
}
else
break;
}

- Srinivas March 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static public List<String> subString(String str){
		
		List<String> lst = new LinkedList<>();

		outer : for(int outer_index = 0; outer_index < str.length(); outer_index++){
			int start_index = str.charAt(outer_index);
			for(int inner_index = outer_index+1; inner_index < str.length(); inner_index++){
				if(start_index < str.charAt(inner_index)){
					lst.add(str.substring(outer_index, inner_index + 1));
					start_index = str.charAt(inner_index);
				}else{
					continue outer;
				}
			}
		}
		return lst;
	}

- Goutham March 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//Scala code for the above

def listIncreasingSubstring(str : String): List[String] = {
    def loop(start : Int, end : Int, result : List[String]) : List[String] = {
      val sub = str.substring(start,end+1)
      //See if this substring is strictly increasing
      val correctStart = everyCharIsGreaterThanLast(str,start,end)
      //Add the substring if it is increasing
      val newResult = if(correctStart) sub :: result else result
      //further loop conditions
      if(end == str.length - 1 && start == str.length - 2) newResult
      //checking correctStart here so that if a substring is not increasing from a fixed start there is no point in checking further from that start
      else if (end == str.length - 1 || !correctStart) loop(start+1,start+2,newResult)
      else loop(start,end+1,newResult)
    }
    loop(0,1,Nil)
  }

  def everyCharIsGreaterThanLast(str: String, start : Int, end: Int) : Boolean = {
    if (start == end) true
    else if(str.charAt(start) >= str.charAt(start+1)) false
    else everyCharIsGreaterThanLast(str,start+1,end)
  }

- Joey March 10, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static Set<String> generateSubStringsOfLength2(final String input) {

Set<String> substrings = new HashSet<String>();

for(int i=0; i<input.length(); i++) {
for(int j=i+2; j<=input.length(); j++){

substrings.add(input.substring(i,j));
}
}

return substrings;
}

- Sourav March 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static Set<String> generateSubStringsOfLength2(final String input) {

Set<String> substrings = new HashSet<String>();

for(int i=0; i<input.length(); i++) {
for(int j=i+2; j<=input.length(); j++){

substrings.add(input.substring(i,j));
}
}

return substrings;
}

- Sourav March 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hi

- Sourav March 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static Set<String> generateSubStringsOfLength2(final String input) {

Set<String> substrings = new HashSet<String>();

for(int i=0; i<input.length(); i++) {
for(int j=i+2; j<=input.length(); j++){

substrings.add(input.substring(i,j));
}
}

return substrings;
}

- Anonymous March 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static List<String> count(String str) {
		if(str == null || str.length() == 0) return null;
		List<String> ans = new ArrayList<>();
		for(int i=0; i<str.length(); i++){
			StringBuilder sb = new StringBuilder();
			sb.append(str.charAt(i));
			for(int j=i+1; j<str.length(); j++){
				sb.append(str.charAt(j));
				if(str.charAt(j-1) < str.charAt(j))
					//ans.add(str.substring(i,j+1));
					ans.add(sb.toString());
				else // If subarray arr[i..j] is not strictly increasing, then subarrays after it , i.e., 
		            // arr[i..j+1], arr[i..j+2], .... cannot be strictly increasing
					break;
			}
		}
		
		return ans;

- hulk March 29, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static List<String> count(String str) {
		if(str == null || str.length() == 0) return null;
		List<String> ans = new ArrayList<>();
		for(int i=0; i<str.length(); i++){
			StringBuilder sb = new StringBuilder();
			sb.append(str.charAt(i));
			for(int j=i+1; j<str.length(); j++){
				sb.append(str.charAt(j));
				if(str.charAt(j-1) < str.charAt(j))
					//ans.add(str.substring(i,j+1));
					ans.add(sb.toString());
				else // If subarray arr[i..j] is not strictly increasing, then subarrays after it , i.e., 
		            // arr[i..j+1], arr[i..j+2], .... cannot be strictly increasing
					break;
			}
		}
		
		return ans;

- Hulk March 29, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static List<string> getConsecutiveLettersinString(string s)
        {
            List<string> cs = new List<string>();

            for (int i = 0; i < s.Length; i++)
            {
                int k = i;
                for (int j = i + 1; j < s.Length; j++)
                {
                    if (s[k] < s[j])
                    {
                        cs.Add(s.Substring(i, j - i + 1));
                        k++;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return cs;
        }

- Amarender March 30, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void ReturnSubstringGreaterThanTwo(string myString)
        {
            char[] myChar = myString.ToArray();
            List<char> lstChar = new List<char>();
            List<string> lst = new List<string>();
            for (int i = 0; i < myChar.Count() - 1; i++)
            {
                lstChar.Add(myChar[i]);
                for (int j = i+1; j < myChar.Count(); j++)
                {
                    if (myChar[j-1] != myChar[j])
                    {
                        lstChar.Add(myChar[j]);
                        lst.Add(new string(lstChar.ToArray()));
                    }
                    else
                    {
                        break;
                    }
                }
                lstChar.Clear();
            }

            lst.ForEach(s => Console.WriteLine(s));
        }

- Anonymous April 01, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int getLongest( string & orig, int start, set<string>& ans)
{

    int consec = 1;
    for ( int i=start; i < orig.length() -1 ; i++ )
    {
        if ( orig[i+1] == orig[i]+1 )
        {
            consec++;
            if ( consec > 1 )
                ans.insert(orig.substr(start,consec));
        }
        else
            break;
        
    
    }
    return consec;
}

set<string> consecutiveChars(string  orig)
{
    
    set<string> consecutive;

    int start=0;
    while( start < orig.size() )
    {
        start+=getLongest(orig, start,consecutive);
    }
    return consecutive;
}

- drolmal April 02, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

v = "abcdefghijklmnopqrstuvwxyz"
v = {char:i for char,i in zip(v,range(26))}
#print v

def printStr(s):
st = s[0]
for i in range(1,len(s)):
if v[s[i]] - v[st[-1]] == 1:
st += s[i]
else:
for j in range(2,len(st)+1):
for k in range(0,len(st)-j+1):
print st[k:k+j],
st = s[i]
for j in range(2,len(st)+1):
for k in range(0,len(st)-j+1):
print st[k:k+j],
return

- Nitin April 25, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

v = "abcdefghijklmnopqrstuvwxyz"
v = {char:i for char,i in zip(v,range(26))}
#print v

def printStr(s):
    st = s[0]
    for i in range(1,len(s)):
        if v[s[i]] - v[st[-1]] == 1:
            st += s[i]
        else:
            for j in range(2,len(st)+1):
                for k in range(0,len(st)-j+1):
                    print st[k:k+j],            
            st = s[i]
    for j in range(2,len(st)+1):
        for k in range(0,len(st)-j+1):
            print st[k:k+j],
    return

- Nitin April 25, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

v = "abcdefghijklmnopqrstuvwxyz"
v = {char:i for char,i in zip(v,range(26))}
#print v

def printStr(s):
    st = s[0]
    for i in range(1,len(s)):
        if v[s[i]] - v[st[-1]] == 1:
            st += s[i]
        else:
            for j in range(2,len(st)+1):
                for k in range(0,len(st)-j+1):
                    print st[k:k+j],            
            st = s[i]
    for j in range(2,len(st)+1):
        for k in range(0,len(st)-j+1):
            print st[k:k+j],
    return

- Nitin April 25, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static List<string> GetSubString(string inputString)
    {
      List<string> subString = new List<string>();
      for (int i = 0; i <inputString.Length; i++)
      {
        int k = i;
        for (int j = i + 1; j < inputString.Length; j++)
        {
          if (inputString[k] < inputString[j])
          {
            if (j >= 2)
            {
              if (inputString[j] <= inputString[j - 1])
              {
                break;
              }
            }
            subString.Add(inputString.Substring(i,j-i+1));
          }
          else
          {
            break;
          }
        }
      }
        return subString;
    }

Input --> BCCDDEEFG
Output --> BC, CD, DE, EF, EFG, FG

- SanR May 09, 2017 | 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