I recently had a mock interview with Meta (formerly Facebook) for the E4 position, and I wanted to share my experience and the questions that were asked. The interview consisted of two coding questions, and I'd like to give you a brief overview of what they entailed.
Question 1: Add Strings
Problem Description: You are given two non-negative integers represented as strings. Write a function to return their sum as a string.
My Approach: I solved this problem by simulating the addition process, just like how we do it on paper. I iterated through both strings from the rightmost digit to the leftmost digit, adding the corresponding digits and keeping track of carry. It's a straightforward problem, but you need to handle corner cases and carry efficiently.
Question 2: Validate Binary Search Tree
Problem Description: Given a binary tree, determine if it is a valid binary search tree (BST).
My Approach: To validate a binary search tree, I employed a recursive approach, which is quite common for this problem. At each node, I checked if it satisfies the BST property by comparing its value with the maximum and minimum values it should have based on its position in the tree. This way, I ensured that all left children are smaller, and all right children are larger than their parent node.
I'm sharing my experience and these problem links in the hope that they may help someone else preparing for interviews with Meta or other tech companies. Happy coding!