facebook-interview-questions

Implement Queue using Stacks Cover Image
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.

Find Product of Array Except Self Cover Image
Find Product of Array Except Self

Given an array X[] of n integers, write a program to find an array product[] such that product[i] is equal to the product of all the elements of X[] except X[i]. We need to solve this problem without using division operations. This is an excellent problem to learn problem-solving using prefix array and a single loop.

Move all Zeroes to the End of an Array Cover Image
Move all Zeroes to the 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.

Check for pair in an array with a given sum Cover Image
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.

Remove duplicates from sorted array Cover Image
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.

Rotate a matrix by 90 degrees Cover Image
Rotate a matrix by 90 degrees

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

Intersection of Two Unsorted Arrays Cover Image
Intersection of Two Unsorted Arrays

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

Maximum difference in an array Cover Image
Maximum difference in an array

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. This is an excellent problem to learn problem-solving using divide and conquer, transform and conquer and a single loop.

Find the minimum and maximum value in an array Cover Image
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.

Sort an array of 0s, 1s, and 2s —Dutch National Flag Problem Cover Image
Sort an array of 0s, 1s, and 2s —Dutch National Flag Problem

Given an array X[] 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.

Minimum in a Rotated and Sorted Array Cover Image
Minimum in a Rotated and Sorted Array

A sorted and rotated array of size n is given, write a program to find the minimum element in the array. Rotation by k times means that the first k sorted elements of the array will move to the last k positions, and the last n - k sorted elements move to the first n - k positions (in an anti-clockwise fashion).

Container With Most Water Problem Cover Image
Container With Most Water Problem

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 form a container, such that the container contains the most water.

Triplet with Zero Sum Cover Image
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. For example, suppose such triplets in the array are X[i], X[j] and X[k] then X[i] + X[j] + X[k] = 0. Note : solution set must not contain duplicate triplets.

Minimum Depth of a Binary Tree Cover Image
Minimum 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.

Roman to Integer Cover Image
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.

Find most frequent element in an array Cover Image
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.

Our weekly newsletter

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

© 2022 Code Algorithms Pvt. Ltd.

All rights reserved.