Giter Site home page Giter Site logo

basemax / interviewfaang Goto Github PK

View Code? Open in Web Editor NEW
31.0 3.0 5.0 90 KB

Solving Facebook interview questions.

License: GNU General Public License v3.0

PHP 18.59% Python 81.41%
interview interview-questions interview-preparation interview-practice interview-test interview-facebook facebook faang

interviewfaang's Introduction

FAANG Interview

I took a Job offer from Google 1 years ago, and took another Job offer from FB a few days ago to work as a Technical Lead, Senior Software engineer.

So I try to solve some Facebook interview and this was really cool for me.

I will add more tasks soon one by one, So it's a source for watching popular questions...

Solving Facebook interview questions

Pretty Json

Asked in: Facebook, Microsoft

Given a string A representating json object. Return an array of string denoting json object with proper indentaion.

Rules for proper indentaion:

  • Every inner brace should increase one indentation to the following lines.
  • Every close brace should decrease one indentation to the same line and the following lines.
  • The indents can be increased with an additional ‘\t’

Note:

  • [] and {} are only acceptable braces in this case.
  • Assume for this problem that space characters can be done away with.
Input Format

The only argument given is the integer array A.

Output Format

Return a list of strings, where each entry corresponds to a single line. The strings should not have "\n" character in them.

For Example
Input 1:
    A = "{A:"B",C:{D:"E",F:{G:"H",I:"J"}}}"
Output 1:
    { 
        A:"B",
        C: 
        { 
            D:"E",
            F: 
            { 
                G:"H",
                I:"J"
            } 
        } 
    }

Input 2:
    A = ["foo", {"bar":["baz",null,1.0,2]}]
Output 2:
   [
        "foo", 
        {
            "bar":
            [
                "baz", 
                null, 
                1.0, 
                2
            ]
        }
    ]

Integer To Roman

Asked in: Amazon, Facebook, Microsoft, Twitter

Please Note:

Another question which belongs to the category of questions which are intentionally stated vaguely. Expectation is that you will ask for correct clarification or you will state your assumptions before you start coding.

Given an integer A, convert it to a roman numeral, and return a string corresponding to its roman numeral version

Note : This question has a lot of scope of clarification from the interviewer. Please take a moment to think of all the needed clarifications and see the expected response using “See Expected Output”

For the purpose of this question, https://projecteuler.net/about=roman_numerals has very detailed explanations.

Input Format

The only argument given is integer A.

Output Format

Return a string denoting roman numeral version of A.

Constraints

1 <= A <= 3999

For Example
Input 1:
    A = 5
Output 1:
    "V"

Input 2:
    A = 14
Output 2:
    "XIV"

Roman To Integer

Asked in: Amazon, Facebook, Microsoft, Twitter

Given a string A representing a roman numeral. Convert A into integer.

A is guaranteed to be within the range from 1 to 3999.

NOTE: Read more details about roman numerals at Roman Numeric System

Input Format

The only argument given is string A.

Output Format

Return an integer which is the integer verison of roman numeral string.

For Example
Input 1:
    A = "XIV"
Output 1:
    14

Input 2:
    A = "XX"
Output 2:
    20

Add Two Numbers as Lists

Asked in: Amazon, Qualcomm, Microsoft, Facebook

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

  • Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)

  • Output: 7 -> 0 -> 8

    342 + 465 = 807

Make sure there are no trailing zeros in the output list So, 7 -> 0 -> 8 -> 0 is not a valid response even though the value is still 807.

Count And Say

Asked in: Facebook, Amazon

The count-and-say sequence is the sequence of integers beginning as follows:

1, 11, 21, 1211, 111221, ...
  • 1 is read off as one 1 or 11.
  • 11 is read off as two 1s or 21.
  • 21 is read off as one 2, then one 1 or 1211.

Given an integer n, generate the nth sequence.

Note: The sequence of integers will be represented as a string. Each term of the sequence of integers will be represented as a string.

The count-and-say sequence is the sequence of integers with the first five terms as following:

1.     1
2.     11
3.     21
4.     1211
5.     111221

Given an integer n where 1 ≤ n ≤ 30, generate the nth term of the count-and-say sequence. You can do so recursively, in other words from the previous member read off the digits, counting the number of digits in groups of the same digit.

Example:

if n = 2, the sequence is 11.

Example 1:

Input: 1
Output: "1"
Explanation: This is the base case.

Example 2:

Input: 4
Output: "1211"
Explanation: For n = 3 the term was "21" in which we have two groups "2" and "1", "2" can be read as "12" which means frequency = 1 and value = 2, the same way "1" is read as "11", so the answer is the concatenation of "12" and "11" which is "1211".

Add Binary Strings

Asked in: Facebook, Microsoft

Given two binary strings, return their sum (also a binary string).

Example:
a = "100"
b = "11"
Return a + b = “111”.

Reverse the String

Asked in: Qualcomm, Amazon, Microsoft, Cisco, Facebook

Given a string A.

Return the string A after reversing the string word by word.

NOTE: A sequence of non-space characters constitutes a word. Your reversed string should not contain leading or trailing spaces, even if it is present in the input string. If there are multiple spaces between words, reduce them to a single space in the reversed string.

Input Format

The only argument given is string A.

Output Format

Return the string A after reversing the string word by word.

For Example
Input 1:
    A = "the sky is blue"
Output 1:
    "blue is sky the"

Input 2:
    A = "this is ib"
Output 2:
    "ib is this"

Sort by Color

Asked in: Facebook, Microsoft

Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.

Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.

Note: Using library sort function is not allowed.

Example :
Input : [0 1 2 0 1 2]
Modify array so that it becomes : [0 0 1 1 2 2]

Best Time to Buy and Sell Stocks I

Asked in: Amazon, Facebook

Say you have an array, A, for which the ith element is the price of a given stock on day i.

If you were only permitted to complete at most one transaction (i.e, buy one and sell one share of the stock), design an algorithm to find the maximum profit.

Return the maximum possible profit.

Problem Constraints

0 <= len(A) <= 7e5

1 <= A[i] <= 1e7

Input Format

The first and the only argument is an array of integers, A.

Output Format

Return an integer, representing the maximum possible profit.

Example Input

Input 1:
A = [1, 2]
Output 2:
4

Input 2:
A = [1, 4, 5, 2, 4]
Output 1:
1

Example Explanation

Explanation 1:

Buy the stock on day 0, and sell it on day 1.

Explanation 2:

Buy the stock on day 0, and sell it on day 2.

Implement StrStr

Asked in: Facebook, Amazon, Qualcomm, Wipro, Microsoft

Please Note: Another question which belongs to the category of questions which are intentionally stated vaguely. Expectation is that you will ask for correct clarification or you will state your assumptions before you start coding.

Implement strStr(): strstr - locate a substring ( needle ) in a string ( haystack ).

Try not to use standard library string functions for this question.

Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.


Max Base

My nickname is Max, Programming language developer, Full-stack programmer. I love computer scientists, researchers, and compilers. (Max Base)

Asrez Team

A team includes some programmer, developer, designer, researcher(s) especially Max Base.

Asrez Team

interviewfaang's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.