Microsoft | SWE Intern | Syracuse University | Summer 2020 [pass]

Question 1:
Tell me about an experience about how your collaborate with your colleagus? (Be specific).

Question 2:
Write a function to print the numbers from 1 to 100, when number % 3 == 0, print "Three", when number % 5 == 0, print "Five", otherwise print the number.
Follow-up: how to test this function? (I am not sure what this question means).

Example:

1--1
2--2
3--Three
4--4
5--Five
6--Three
.
.
.
15--Three Five
My solution
public static void main(String[] args){
	for(int i = 1; i <= 100; i ++){
		System.out.println(print(i));
	}
}

private String print(int n){
	String str = "";
	if(n % 3 != 0 && n % 5 != 0)
		str += String.valueOf(n);
	else {
		if(n % 3 == 0)
			str += "Three";
		if(n % 5 == 0){
			if(!str.equals(""))
				str += " ";
			str += "Five";	
		}
	}
	return str;
}

Question 3:
What's the difference between Graph and Tree?
Follow-up: write a function to determine whether a Graph is tree or not?

My solution
class Node {
	public int val;
	public List<Node> neighbors;
	public Node(){}
	public Node(int _val, List<Node> _neighbors){
		val = _val;
		neighbors = _neighbors;
	}
};

public boolean isTree(Node node){
	Set<Node> set = new HashSet<>();
	Stack<Node> st = new Stack<>();
	st.push(node);
	while(!st.empty()){
		node = st.pop();
		if(set.contains(node)) return false;
		set.add(node);
		for(Node next : node.neighbors){
			if(next != null)
				st.push(next);
		}
	}
	return true;
}
Thank @MikeBonzai I made a terrible mistake.

Another funny story, right after my interview, my professor talked about Trees at his class.
image

Comments (5)