Facebook onsite interview experience

Status: Working as Software Engineer in SFO.
Location: Menlo Park, CA

Phone Interview: (60 mins)

Quick intro about 5 mins
Then https://leetcode.com/problems/merge-intervals/
At the end 5 mins for me to ask questions

Onsite Interview

Round One: (behavior)

  1. Tell me about yourself?
  2. Tell me about the challenge you faced in your current project?
  3. How do you manage to solve the challenge?
  4. Tell me about the time you receive a positive feedback from your manager?

Round Two: (codding)

  1. Valid Number - https://leetcode.com/problems/valid-number/
  2. Verify that an input array is sorted according to the order defined by another array – a variation of https://www.geeksforgeeks.org/sort-array-according-order-defined-another-array/

Lunch: You can ask any question you have.

Round Three: (design)

  1. Design a system like Hacker Rank for a programming contest and their ranking.

Round Four: (coding)

  1. Serialize and Deserialized Binary Tree - https://leetcode.com/problems/serialize-and-deserialize-binary-tree/

Round Five: (discussion/coding)

Initial facebook interview was set up for 45 min and an interviewer asked a single programming question. This interview was Seattle USA.

Question:
Consolidate time for each function.

/*
Function stage(start/ends) time(start/end)
main start 0
<----------- main running
foo start 3
foo end 7
<----------- main running
zoo start 10
zoo end 13
<-------------- main running
moo start 15
foo start 17
foo end 18
<---------------- moo running
moo end 20
< --------------main running
main end 22

Consolidate time for each function.
*/

Solution

	class LogInfo
	{
		String functionName;
		String timeType;
		int time;


		LogInfo(String functionName, String timeType, int time)
		{
			this.functionName = functionName;
			this.timeType = timeType;
			this.time = time;
		}
	}

	class LogOfStack
	{
		String functionName;
		int startime;
		int totalTime;


		LogOfStack(String functionName, int startime, int totalTime)
		{
			this.functionName = functionName;
			this.startime = startime;
			this.totalTime = totalTime;
		}
	}


	public Map<String, Integer> consolidation(List<LogInfo> logInfos)
	{
		final Map<String, Integer> map = new HashMap<>();
		final Stack<LogOfStack> activeStack = new Stack<>();
		for (final LogInfo info : logInfos)
		{
			if (info.timeType.equals("start"))
			{
				if (!activeStack.isEmpty())
				{
					final LogOfStack previous = activeStack.peek();
					previous.totalTime = previous.totalTime + info.time - previous.startime;
					previous.startime = info.time;
				}

				activeStack.push(new LogOfStack(info.functionName, info.time, 0));
			}
			else
			{
				LogOfStack previous = activeStack.pop();
				previous.totalTime = previous.totalTime + info.time - previous.startime;
				if (!map.containsKey(info.functionName))
				{
					map.put(info.functionName, 0);
				}

				final int time = map.get(info.functionName) + previous.totalTime;
				map.put(info.functionName, time);

				if (!activeStack.isEmpty())
				{
					previous = activeStack.peek();
					previous.startime = info.time;
				}
			}
		}

		return map;
	}


	public static void main(String[] arg)
	{
		Facebook facebook = new Facebook();
		String main = "main";
		String foo = "foo";
		String zoo = "zoo";
		String moo = "moo";
		String pee = "pee";
		List<LogInfo> logInfos = new ArrayList<>();
		logInfos.add(facebook.new LogInfo(main, "start", 0));
		logInfos.add(facebook.new LogInfo(foo, "start", 3));
		logInfos.add(facebook.new LogInfo(foo, "end", 7));
		logInfos.add(facebook.new LogInfo(zoo, "start", 10));
		logInfos.add(facebook.new LogInfo(zoo, "end", 13));
		logInfos.add(facebook.new LogInfo(moo, "start", 15));
		logInfos.add(facebook.new LogInfo(foo, "start", 16));
		logInfos.add(facebook.new LogInfo(pee, "start", 17));
		logInfos.add(facebook.new LogInfo(pee, "end", 18));
		logInfos.add(facebook.new LogInfo(foo, "end", 18));
		logInfos.add(facebook.new LogInfo(moo, "end", 20));
		logInfos.add(facebook.new LogInfo(main, "end", 22));

		System.out.println(facebook.consolidation(logInfos));

	}

}

https://leetcode.com/problems/exclusive-time-of-functions/description/