Meta (Facebook) Coding Interview Questions

Review this list of 55 Meta (Facebook) coding interview questions and answers verified by hiring managers and candidates.
  • +8

    "Answer: select fromcaller, count(DISTINCT tocallee) as num_calls from calls group by fromcaller having count(DISTINCT tocallee) >= 3 Setup: CREATE TABLE calls ( from_caller VARCHAR(20), to_callee VARCHAR(20) ); INSERT INTO calls (fromcaller, tocallee) VALUES ('Alice', 'Bob'), ('Charlie', 'Dave'), ('Alice', 'Frank'), ('Charlie', 'Heidi'), ('Charlie', 'Judy'); "

    KAI - "Answer: select fromcaller, count(DISTINCT tocallee) as num_calls from calls group by fromcaller having count(DISTINCT tocallee) >= 3 Setup: CREATE TABLE calls ( from_caller VARCHAR(20), to_callee VARCHAR(20) ); INSERT INTO calls (fromcaller, tocallee) VALUES ('Alice', 'Bob'), ('Charlie', 'Dave'), ('Alice', 'Frank'), ('Charlie', 'Heidi'), ('Charlie', 'Judy'); "See full answer

    Data Scientist
    Coding
    +1 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    +30

    "Was this for an entry level engineer role?"

    Yeshwanth D. - "Was this for an entry level engineer role?"See full answer

    Software Engineer
    Coding
    +4 more
  • +20

    "Since the problem asks for a O(logN) solution, I have to assume that the numbers are already sorted, meaning the same number are adjacent to each other, the value of the numbers shouldn't matter, and they expect us to use Binary Search. First, we should analyze the pattern of a regular number array without a single disrupter. Index: 0 1 2 3 4. 5 6. 7. 8. 9 Array:[1, 1, 2, 2, 4, 4, 5, 5, 6, 6] notice the odd indexes are always referencing the second of the reoccurring numbers and t"

    Bamboo Y. - "Since the problem asks for a O(logN) solution, I have to assume that the numbers are already sorted, meaning the same number are adjacent to each other, the value of the numbers shouldn't matter, and they expect us to use Binary Search. First, we should analyze the pattern of a regular number array without a single disrupter. Index: 0 1 2 3 4. 5 6. 7. 8. 9 Array:[1, 1, 2, 2, 4, 4, 5, 5, 6, 6] notice the odd indexes are always referencing the second of the reoccurring numbers and t"See full answer

    Software Engineer
    Coding
  • Software Engineer
    Coding
    +1 more
  • +8

    "Used Recursive approach to traverse the binary search tree and sum the values of the nodes that fall within the specified range [low, high]"

    Srikant V. - "Used Recursive approach to traverse the binary search tree and sum the values of the nodes that fall within the specified range [low, high]"See full answer

    Software Engineer
    Coding
    +1 more
  • 🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.

  • "find total sum. assign that to rightsum traverse from left to right: keep updating left sum and right sum, when they match return the index. else if you reach end return -1 or not found"

    Rahul J. - "find total sum. assign that to rightsum traverse from left to right: keep updating left sum and right sum, when they match return the index. else if you reach end return -1 or not found"See full answer

    Software Engineer
    Coding
    +1 more
  • "SELECT s.Sale_Date, SUM(si.Quantity * si.SalePrice) AS TotalRevenue FROM Sales s JOIN SaleItems si ON s.SaleID = si.Sale_ID GROUP BY s.Sale_Date ORDER BY s.Sale_Date; "

    Bala G. - "SELECT s.Sale_Date, SUM(si.Quantity * si.SalePrice) AS TotalRevenue FROM Sales s JOIN SaleItems si ON s.SaleID = si.Sale_ID GROUP BY s.Sale_Date ORDER BY s.Sale_Date; "See full answer

    Data Engineer
    Coding
    +1 more
  • Software Engineer
    Coding
    +1 more
  • "WITH ActiveUsersYesterday AS ( SELECT DISTINCT user_id FROM user_activity WHERE activity_date = CAST(GETDATE() - 1 AS DATE) ), VideoCallUsersYesterday AS ( SELECT DISTINCT user_id FROM video_calls WHERE call_date = CAST(GETDATE() - 1 AS DATE) ) SELECT (CAST(COUNT(DISTINCT v.userid) AS FLOAT) / NULLIF(COUNT(DISTINCT a.userid), 0)) * 100 AS percentagevideocall_users FROM ActiveUsersYesterday a LEFT JOIN VideoCallUsersYesterday v ON a.userid = v.userid;"

    Bala G. - "WITH ActiveUsersYesterday AS ( SELECT DISTINCT user_id FROM user_activity WHERE activity_date = CAST(GETDATE() - 1 AS DATE) ), VideoCallUsersYesterday AS ( SELECT DISTINCT user_id FROM video_calls WHERE call_date = CAST(GETDATE() - 1 AS DATE) ) SELECT (CAST(COUNT(DISTINCT v.userid) AS FLOAT) / NULLIF(COUNT(DISTINCT a.userid), 0)) * 100 AS percentagevideocall_users FROM ActiveUsersYesterday a LEFT JOIN VideoCallUsersYesterday v ON a.userid = v.userid;"See full answer

    Data Scientist
    Coding
    +2 more
  • +2

    "class Solution { public boolean isValid(String s) { // Time Complexity and Space complexity will be O(n) Stack stack=new Stack(); for(char c:s.toCharArray()){ if(c=='('){ stack.push(')'); } else if(c=='{'){ stack.push('}'); } else if(c=='['){ stack.push(']'); } else if(stack.pop()!=c){ return false; } } return stack.isEmpty(); } }"

    Kanishvaran P. - "class Solution { public boolean isValid(String s) { // Time Complexity and Space complexity will be O(n) Stack stack=new Stack(); for(char c:s.toCharArray()){ if(c=='('){ stack.push(')'); } else if(c=='{'){ stack.push('}'); } else if(c=='['){ stack.push(']'); } else if(stack.pop()!=c){ return false; } } return stack.isEmpty(); } }"See full answer

    Machine Learning Engineer
    Coding
    +2 more
  • +2

    "Implemented a recursive function which returns the length of the list so far. when the returned value equals k + 1 , assign current.next = current.next.next. If I made it back to the head return root.next as the new head of the linked list."

    דניאל ר. - "Implemented a recursive function which returns the length of the list so far. when the returned value equals k + 1 , assign current.next = current.next.next. If I made it back to the head return root.next as the new head of the linked list."See full answer

    Machine Learning Engineer
    Coding
    +2 more
  • +2

    "Traverse the array of points while computing the distance and pushing it to the heap. Then traverse again the heap and pop the k closest. Time O(nlogn) Space O(n)"

    Dadja Z. - "Traverse the array of points while computing the distance and pushing it to the heap. Then traverse again the heap and pop the k closest. Time O(nlogn) Space O(n)"See full answer

    Software Engineer
    Coding
    +2 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    Video answer for 'Explain how to find a target sum in an array.'
    +4

    "a top-down recursive solution with memoization in python: from typing import List from functools import cache def changeSigns(nums: List[int], S: int) -> int: @cache def dp(i, curr_sum): if i == len(nums): if curr_sum == S: return 1 return 0 return dp(i+1, currsum + nums[i]) + dp(i+1, currsum - nums[i]) answer = dp(0, 0) if answer == 0: return -1 return answer `"

    Jessica R. - "a top-down recursive solution with memoization in python: from typing import List from functools import cache def changeSigns(nums: List[int], S: int) -> int: @cache def dp(i, curr_sum): if i == len(nums): if curr_sum == S: return 1 return 0 return dp(i+1, currsum + nums[i]) + dp(i+1, currsum - nums[i]) answer = dp(0, 0) if answer == 0: return -1 return answer `"See full answer

    Software Engineer
    Coding
    +1 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    Software Engineer
    Coding
    +1 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    Video answer for 'Merge Intervals'
    +35

    "const mergeIntervals = (intervals) => { const compare = (a, b) => { if(a[0] b[0]) return 1 else if(a[0] === b[0]) { return a[1] - b[1] } } let current = [] const result = [] const sorted = intervals.sort(compare) for(let i = 0; i = b[0]) current[1] = b[1] els"

    Kofi N. - "const mergeIntervals = (intervals) => { const compare = (a, b) => { if(a[0] b[0]) return 1 else if(a[0] === b[0]) { return a[1] - b[1] } } let current = [] const result = [] const sorted = intervals.sort(compare) for(let i = 0; i = b[0]) current[1] = b[1] els"See full answer

    Software Engineer
    Coding
    +6 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    +16

    "function isValid(s) { const stack = []; for (let i=0; i < s.length; i++) { const char = s.charAt(i); if (['(', '{', '['].includes(char)) { stack.push(char); } else { const top = stack.pop(); if ((char === ')' && top !== '(') || (char === '}' && top !== '{') || (char === ']' && top !== '[')) { return false; } } } return stack.length === 0"

    Tiago R. - "function isValid(s) { const stack = []; for (let i=0; i < s.length; i++) { const char = s.charAt(i); if (['(', '{', '['].includes(char)) { stack.push(char); } else { const top = stack.pop(); if ((char === ')' && top !== '(') || (char === '}' && top !== '{') || (char === ']' && top !== '[')) { return false; } } } return stack.length === 0"See full answer

    Software Engineer
    Coding
    +4 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    Video answer for 'Move all zeros to the end of an array.'
    +44

    "this solution here is much faster than the exponent reference soln. It is also far more concise and easy to understand def moveZerosToEnd(arr: List[int]) -> List[int]: left = 0 for right in range(len(arr)): if arr[right] == 0: pass else: if left != right: temp = arr[left] arr[left] = arr[right] arr[right] = temp left += 1 return arr `"

    Devesh K. - "this solution here is much faster than the exponent reference soln. It is also far more concise and easy to understand def moveZerosToEnd(arr: List[int]) -> List[int]: left = 0 for right in range(len(arr)): if arr[right] == 0: pass else: if left != right: temp = arr[left] arr[left] = arr[right] arr[right] = temp left += 1 return arr `"See full answer

    Machine Learning Engineer
    Coding
    +4 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    +1

    "public class CircularBuffer { private T[] buffer; private int head; private int tail; private int size; private final int capacity; public CircularBuffer(int capacity) { this.capacity = capacity; this.buffer = (T[]) new Object[capacity]; this.head = 0; this.tail = 0; this.size = 0; } public void enqueue(T item) { if (isFull()) { throw new IllegalStateException("Buffer is full"); } buf"

    Vidhyadhar V. - "public class CircularBuffer { private T[] buffer; private int head; private int tail; private int size; private final int capacity; public CircularBuffer(int capacity) { this.capacity = capacity; this.buffer = (T[]) new Object[capacity]; this.head = 0; this.tail = 0; this.size = 0; } public void enqueue(T item) { if (isFull()) { throw new IllegalStateException("Buffer is full"); } buf"See full answer

    Software Engineer
    Coding
    +1 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    Video answer for 'Implement k-means clustering.'

    "i dont know"

    Dinesh K. - "i dont know"See full answer

    Machine Learning Engineer
    Coding
    +5 more
  • "Write a function which Caesar ciphers all the strings so that the first character is "a". Use ascii code points and the modulo operator to do this. Use this function to create a hashmap between each string and the CC-a string. Then go through each key:value pair in the hashmap, and use the CC-a ciphered value as the key in a new defaultdict(list), adding the original string to the value field in the output."

    Michael B. - "Write a function which Caesar ciphers all the strings so that the first character is "a". Use ascii code points and the modulo operator to do this. Use this function to create a hashmap between each string and the CC-a string. Then go through each key:value pair in the hashmap, and use the CC-a ciphered value as the key in a new defaultdict(list), adding the original string to the value field in the output."See full answer

    Machine Learning Engineer
    Coding
    +1 more
Showing 1-20 of 55