


Facebook Software Developer Interview Questions and Answers for Freshers
Q1. Path Counting in Directed Graph
Given a directed graph with a specified number of vertices V
and edges E
, your task is to calculate the total number of distinct paths from a given source node S
to all other no...read more
Calculate the total number of distinct paths from a given source node to all other nodes in a directed graph.
Use dynamic programming to keep track of the number of paths from the source node to each node in the graph.
Consider using modular arithmetic to handle large numbers and prevent overflow.
Start by initializing the number of paths from the source node to itself as 1.
Iterate through the edges of the graph and update the number of paths for each destination node.
Return the...read more
Q2. Longest Route Problem Statement
Given a 2-dimensional binary matrix called Mat
of size N x M that consists solely of 0s and 1s, find the length of the longest path from a specified source cell to a destination ...read more
Find the length of the longest path from a source cell to a destination cell in a binary matrix.
Use depth-first search (DFS) to explore all possible paths from source to destination.
Keep track of visited cells to avoid revisiting them.
Return the length of the longest path found, or -1 if no path exists.
Q3. Course Schedule II Problem Statement
You are provided with a number of courses 'N', some of which have prerequisites. There is a matrix named 'PREREQUISITES' of size 'M' x 2. This matrix indicates that for ever...read more
Given courses with prerequisites, determine a valid order to complete all courses.
Use topological sorting to find a valid order of courses.
Create a graph with courses as nodes and prerequisites as edges.
Start with courses that have no prerequisites and remove them from the graph.
Continue this process until all courses are taken or there are no valid courses left.
If there is a cycle in the graph, it is impossible to complete all courses.
Q4. Merge Intervals Problem Statement
You are provided with 'N' intervals, each containing two integers denoting the start time and end time of the interval.
Your task is to merge all overlapping intervals and retu...read more
Merge overlapping intervals and return sorted list of merged intervals.
Sort the intervals based on start times.
Iterate through intervals and merge overlapping intervals.
Return the merged intervals in sorted order.
Q5. Search In Rotated Sorted Array Problem Statement
Given a rotated sorted array ARR
of size 'N' and an integer 'K', determine the index at which 'K' is present in the array.
Note:
1. If 'K' is not present in ARR,...read more
Given a rotated sorted array, find the index of a given integer 'K'.
Use binary search to find the pivot point where the array is rotated.
Then perform binary search on the appropriate half of the array to find 'K'.
Handle cases where 'K' is not present in the array by returning -1.
Q6. Rank from Stream Problem Statement
Given an array of integers ARR
and an integer K
, determine the rank of the element ARR[K]
.
Explanation:
The rank of any element in ARR
is defined as the number of elements sma...read more
Given an array and an index, find the number of elements smaller than the element at that index appearing before it in the array.
Iterate through the array up to index K and count the number of elements smaller than ARR[K].
Return the count as the rank of ARR[K].
Handle edge cases like empty array or invalid index K.
Q7. LRU Cache Design Question
Design a data structure for a Least Recently Used (LRU) cache that supports the following operations:
1. get(key)
- Return the value of the key if it exists in the cache; otherwise, re...read more
Design a Least Recently Used (LRU) cache data structure that supports get and put operations with capacity constraint.
Implement a doubly linked list to maintain the order of recently used keys.
Use a hashmap to store key-value pairs for quick access.
Update the order of keys in the linked list on get and put operations.
Evict the least recently used key when the cache reaches its capacity.
Q8. Longest Increasing Subsequence Problem Statement
Given an array of integers with 'N' elements, determine the length of the longest subsequence where each element is greater than the previous element. This subse...read more
Find the length of the longest strictly increasing subsequence in an array of integers.
Use dynamic programming to solve this problem efficiently.
Initialize an array to store the length of the longest increasing subsequence ending at each index.
Iterate through the array and update the length of the longest increasing subsequence for each element.
Return the maximum value in the array as the result.
Interview Process at Facebook Software Developer for Freshers

Top Software Developer Interview Questions from Similar Companies








Reviews
Interviews
Salaries
Users/Month

