Add office photos
Facebook logo
Employer?
Claim Account for FREE

Facebook

4.3
based on 161 Reviews
Video summary
Filter interviews by
Software Developer
Fresher
Skills
Clear (2)

Facebook Software Developer Interview Questions and Answers for Freshers

Updated 5 Feb 2024

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

Ans.

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

View 2 more answers
right arrow

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

Ans.

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.

Add your answer
right arrow

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

Ans.

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.

Add your answer
right arrow

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

Ans.

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.

Add your answer
right arrow
Discover Facebook interview dos and don'ts from real experiences

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
Ans.

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.

Add your answer
right arrow

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

Ans.

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.

Add your answer
right arrow

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

Ans.

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.

Add your answer
right arrow

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

Ans.

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.

Add your answer
right arrow
Contribute & help others!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos

Interview Process at Facebook Software Developer for Freshers

based on 1 interviews
Interview experience
5.0
Excellent
View more
interview tips and stories logo
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top Software Developer Interview Questions from Similar Companies

Oracle Logo
3.7
 • 45 Interview Questions
Ericsson Logo
4.1
 • 16 Interview Questions
View all
Recently Viewed
INTERVIEWS
Newgen Software Technologies
10 top interview questions
INTERVIEWS
Systems Technology Group Inc.
10 top interview questions
SALARIES
Atos
INTERVIEWS
American Express
10 top interview questions
INTERVIEWS
Amazon
100 top interview questions
INTERVIEWS
Goldman Sachs
50 top interview questions
INTERVIEWS
Akamai Technologies
20 top interview questions
INTERVIEWS
Cognizant
Fresher
10 top interview questions
INTERVIEWS
Excelon Solutions
10 top interview questions
INTERVIEWS
Standard Chartered
10 top interview questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
75 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter