All content related to facebook-interview-questions

Find the Intersection of Two Unsorted Arrays

Given two integer arrays X[] and Y[] of size m and n, respectively, write a program to find the intersection of these two arrays. The intersection of two arrays is a list of distinct numbers which are present in both arrays. The numbers in the intersection can be in any order.

EnjoyAlgorithms

Triplet with zero sum

Given an array X[] of distinct elements, write a program to find all the unique triplets in the array whose sum is equal to zero.

EnjoyAlgorithms

Implement Queue using Stacks

Write a program to Implement a queue using the stack. The implemented queue should support standard operations like enqueue, dequeue, and front. This is an excellent problem to learn problem-solving and visualize the use case of stack and queue operations.

EnjoyAlgorithms

Find Min Depth of a Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. The path has to end on a leaf node.

EnjoyAlgorithms

Roman to Integer

Given a Roman numeral, write a program to find its corresponding decimal value. Roman numerals are represented by seven different symbols: I , V, X, L, C, D and M.

EnjoyAlgorithms

The maximum difference between two elements

Given an array A[] of integers, find out the maximum difference between any two elements such that the larger element appears after, the smaller element. In other words, we need to find max(A[j] - A[i]), where A[j] > A[i] and j > i.

EnjoyAlgorithms

Find most frequent element in an array

Given an array X[] of size n, write a program to find the most frequent element in the array, i.e. the element which occurs the most number of times. It is assumed that at least one element is repeated.

EnjoyAlgorithms

Check for pair in an array with a given sum

Given an array of n integers and a target number, write a program to check whether a pair sum exits in the array or not. In other words, we need to check whether pair of elements in the array sum exactly to the target value.

EnjoyAlgorithms

Rotate a matrix by 90 degrees in an anticlockwise direction

Given an n x n 2D matrix representing an image, rotate the image by 90 degrees in an anticlockwise direction.

EnjoyAlgorithms

Remove duplicates from sorted array

Write a program to remove the duplicates from the sorted array. For this we are given a sorted array, the task is to remove the duplicate elements such that there is a single occurrence of each element in the array.

EnjoyAlgorithms

Container With Most Water

Given an array of n non-negative integers height[n], where each represents a point at coordinate (i, height[i]). n vertical lines are drawn such that the two endpoints of line i is at (i, height[i]) and (i, 0).  Write a program to find two lines, which together with the x-axis forms a container, such that the container contains the most water.

EnjoyAlgorithms

Sort an array of 0s, 1s, and 2s —Dutch national flag problem

Given an array a[] consisting of 0s, 1s, and 2s. Write a program to sort the array of 0’s, 1’s, and 2’s in ascending order. This is a famous coding interview problem asked in facebook, microsoft and amazon.

EnjoyAlgorithms

Find the minimum and maximum value in an array

Given an array X[] of size n, we need to find the maximum and minimum element present in the array. This coding problem has been asked during facebook and microsoft interview.

EnjoyAlgorithms

Move Zeroes to End of an Array

Given an array X[] of n elements filled with several integers, some of them being zeroes, write a program to move all the zeroes to the end. This is an excellent coding problem to learn space and time complexity optimization.

EnjoyAlgorithms

Our Weekly Newsletter

Subscribe to get free weekly content on data structure and algorithms, machine learning, system design, oops and math.