Coding Interview Cheat Sheet Python

Posted : admin On 1/29/2022

As a software engineer, cracking a FAANG interview is the ultimate dream come true. Working at one of the world’s top tech companies is an incomparable experience, given the growth opportunity and working on exciting projects. Every year, many candidates apply for positions at FAANGto kickstart their careers ascoding engineersor software developers. But only a handful of them make it to the next round.

Python is one of the most popular programming languages in the world. Some of the world’s most famous companies use Python like Netflix, Google, and Uber. But if you’ve seen our article on developer’s confessions then you already know developers use cheat sheets all the time! To help you learn Python, we here at OneMonth. Python Cheat Sheet: Python is a multi-paradigm general-purpose, object-oriented programming languageIt is a cross-platform programming language.

But here’s some good news -- we have created a programming interview cheat sheetfor software engineersand managers that will help you nail the interview prep game and bag the job of your dreams. Let’s delve deeper into the coding interview cheat sheetto make these interviews an absolute cakewalk.

This article will cover:

  • Resources/website to prepare for FAANGCoding Interview
  • How to Prepare for FAANGCoding Interviews
  • Programming Languages you should master for FAANG coding interviews
  • Final interview preparation tips for FAANG Coding Interviews
  • What should you do once the coding interview is over
  • How to Negotiate a Job Offer
  • Final Words

Resources/Website To Prepare for FAANG Coding Interviews

When it comes toFAANGinterview prep materials, there are a plethora of resources. These resources can help you nail the technical interview rounds without breaking a sweat. You can also sign up for a course like Interview Kickstart that offers one of the best boot camps to help you prepare for FAANG interviews. We have helped over 5,000 software engineers to uplevel and ace technical interviews. The team of experts at Interview Kickstart ensures that all important topics are covered in our curriculum so that your preparation strategy is flawless.

Moreover, our preparatory materials have been designed by experts who have also aced FAANG interviews. We take your interview prep to the next level by giving you access to a host of useful tips, tricks, resources, and assessment tools. If you are looking out for someone to guide you with cracking the coding interview cheat sheet and succeed in technical interviews, get in touch with Interview Kickstart.

How to Prepare for FAANG Coding Interviews

While the exact interview process varies for eachFAANG company, here’s a generic overview of the process:

  • Phone screen interview: A phone interview is the first round of the interview process where recruiters screen candidates from the application pool. You can expect a mix of short programming and behavioral questions. Several candidates find the phone screen interview challenging as you cannot be sure what clicks with the interviewer. To make a solid impression, don’t forget to revisit fundamental programming languages and concepts as part of your interview prepstrategy, as you may expect problems relating to those. Practice as many coding problems as you can in the language you are most comfortable with.
  • Onsite interview: Onsite interviews for most FAANGcompanies typically last throughout the day. You can expect 3 to 4 rounds, each involving a set of coding problems you need to solve. The problems are more situational, aimed at assessing your ability to handle real-life issues you may face as a coding engineer working at FAANG. The core focus areas during this round are coding, algorithm, data structure, and system design.

The acceptance rates of most FAANGcompanies are meager. You need to demonstrate that you can develop optimal solutions for the problem posed to you and shouldn’t need too many attempts to arrive at the solution. That’s why you must write clean code and demonstrate your passion for coding. Ensure that you spend enough time mastering these skills before appearing for the technical rounds.

Please note: Due to the ongoing pandemic, onsite interviews are now conducted virtually.

Programming Languages You Should Master for FAANG Coding Interviews

Mastering programming languages is a non-negotiable if you want to excel in FAANG coding interviews. Programming languages form the building blocks of everything that a software engineer is required to do.

Here’s a list of all coding technologies that should form part of your programming interview cheat sheet before you step inside the interview room.

  • Algorithms: In simple terms, algorithms refer to a formula for solving a problem. The various types of algorithms you should be familiar with include:

Bubble sort, insertion sort, and merge sort: The three classic algorithms are bubble sort, insertion sort, and merge sort. Bubble sort is one of the simplest sorting algorithms. This formula considers an entire array and compares each neighboring number. The numbers are then swapped, and the pattern continues for the whole list. In other words, if adjacent elements are in the wrong order, this algorithm swaps the adjacent elements. The next sorting algorithm is the insertion sort, where the elements are compared with each other in a sequential manner and arranged in a particular order. It is similar to arranging a deck of cards. The final one is merge sort which is also known as a divide and conquer algorithm. It divides an unsorted list into a number of sublists, and each contains a single element. Then it merges these sublists in a repeated fashion to create a new sublist.

String manipulation: Programming languages such as Python, C++, and Delphi use a mechanism for manipulating strings. This is referred to as string manipulation and involves handling, modifying, parsing, and analyzing strings and changing their data.

Searching algorithms: As the name suggests, this algorithm is used for searching elements from a dataset. Searching algorithms are part of various data structures for locating specific elements. There are various types of searching algorithms including binary search, jump search, linear search, and exponential search, etc.

  • Design patterns: Object-oriented software developers use design patterns as solutions to the various problems they may encounter during software development. There are various design patterns one can choose from such as Singleton, Factory, Builder, Facade, and Proxy.

Singleton is the simplest design pattern in Java and provides one of the best ways to create an object. It involves a single class that ensures only a single object is created. Factory is a creational pattern in Java that allows the creation of an object without exposure of creation logic to the client. It also uses a common interface to refer to the created objects. Builder pattern allows the creation of complex objects using simple objects. It is also a creational pattern.

Next is the facade pattern, a structural pattern that can add an interface to existing systems and hide their complexity. It also provides an interface for the users to access the system. Lastly, there is the proxy pattern. This is a structural pattern that creates an object and showcases the functionality to the outer world.

  • Data Structures: Data structures refer to a unique format used for organizing, processing, retrieving, and storing data. A good data structure is an integral part of a good algorithm. It also provides the right techniques to the coding engineers for efficiently handling the data available and developing the correct software modules.

There are various types of data structures that should form part of your programming interview cheat sheet, and as a coding engineer, you should know them inside out. These include:

  1. Array
  2. Stack
  3. Queue
  4. Hash
  5. Tree
  6. Linked List

Final Interview Preparation Tips for FAANG Coding Interviews

Technical interviews can be a tough nut to crack, especially when you are considering a FAANG company. Remember that software programming is a highly competitive field, and if you want to stand out from the rest of the candidates, you need to keep a few things in mind.

No coding interview cheat sheetis complete without tips on preparing for the interviews and what to do (and not do) during the interview process. So here are our top tips to help you:

Do’s and Don’ts Prior to the Interview

  • Keep earphones, paper, and pens handy
  • Find a corner where you won’t be distracted
  • Check your internet connection
  • Make sure the webcam is working fine
  • Decide which programming language you wish to focus on
  • Set up coding shortcuts on your laptop
  • Keep answers for the frequently asked behavioral questions ready
  • Don’t lose your cool
  • Wear comfortable clothing but follow a formal dress code
  • Jot down a few questions you would like to ask at the end of the interview

Do’s and Don’ts During the Introduction:

Coding Interview Cheat Sheet Python Answers

  • Keep the introduction brief. Don’t mention irrelevant facts
  • Highlight information that makes a strong case for why you are applying for the role of a coding engineerat a FAANG company
  • Show your enthusiasm even if you are speaking to the recruiters virtually
  • Don’t sound too rehearsed. Follow the natural flow of conversation

Do’s and Don’ts When You Receive a Coding Question:

  • Ask for clarification if you are not clear about a question
  • Double-check the input format and range that the interviewer wants you to follow
  • Think about the problem carefully before you start explaining your approach
  • Stick to a high-level approach while answering
  • Don’t ignore any piece of information provided to you
  • Don’t start coding right away. Take your time to comprehend the question fully
  • Don’t appear under-confident or unsure about the approach you will take

Do’s and Don’ts During the Coding Interview:

  • Always explain to the interviewer what you are trying to arrive at.
  • Practice the correct coding styles so that you can use variable names, operator spacing, proper indentation
  • Always type at a reasonable speed
  • Check if you can use trivial functions to save time
  • Utilize the hints given by the interviewer
  • Showcase your technical knowledge to the interviewer
  • If you are skipping any steps since it is an interview, make sure to clearly explain to the interviewer that in non-interview settings, what you would have done
  • Devote time to practice whiteboard space management skills
  • Don’t remain quiet during the coding round
  • Don’t use very long or single character names
  • Don’t copy-paste blindly
  • Never interrupt the interviewer as they may be dropping valuable hints
  • Don’t take up too much space on the whiteboard

Do’s and Don’ts Once You Have Completed Coding:

  • Double-check the code to spot if there are any errors
  • Try to include extreme test cases and use your code for testing
  • Mention the time and space complexity of the code
  • Spend time going over how your coding approach would be different if you had more time
  • Never abruptly announce that you have finished writing the code
  • Don’t argue or raise your voice

Do’s and Don’ts To End the Coding Interview:

Ask engaging questions to the interviewer to show that you are genuinely interested in the position. Impressing aFAANG recruiter is no cakewalk. Bring the technical interview to an end by following these tips:

  • Don’t keep quiet. Ask meaningful questions to show that you have done your homework
  • Thank the interviewer for taking the time out for you
  • Gauge the mood of the room and ask about your performance during the interview

What Should You Do Once the Coding Interview Is Over

It’s a good practice to send your interviewer a thank you email once thecoding interview is over. Don’t forget to make a mental note of the questions you were asked during the interview. You can keep a record of all such questions to make a more comprehensive programming interview cheat sheet. You can even prepare programming language-specific cheat sheets to prepare for other interviews. For example, all the questions related to Python can be filed under the python cheat sheet for an interview.

How To Negotiate a Job Offer

Negotiating a job offer from a FAANGcompany can seem daunting. After all, you have just managed to snag a cushy position. You may be wondering if negotiating salary will put you at a disadvantage. But as a software engineer, you deserve the best, and you shouldn’t settle for anything else. Here are our hot tips for negotiating a job offer:

  • Do your homework to find out the salary range for the position. This will give you a fair idea about the room for negotiation.
  • It is best to let the company make the first move and tell you the offer. In case they ask you to give them what you expect, always quote the higher end of the expected salary range.
  • Once you receive the offer, it is time to come back with a counter. But don’t quote a number out of thin air. Ask around, take the advice of software engineers or software developers working in FAANG, speak to other managers, and then give them a number.
  • Ask about the benefits that come along with the compensation. Even if the company is not ready to negotiate on the compensation, try to see if you can get more benefits like health insurance cover for your family members or travel allowance, etc.
  • If you are not happy with the offer, don’t be afraid to walk away. It is better to try elsewhere than forcing yourself to work for a lesser salary package.

Final Words

Perseverance and thorough preparation are crucial to cracking technical interviews at FAANG company. While the process is grueling, with the correct coding interview cheat sheet, your efforts will pay off.

We hope this article helps you during the interview prep and land the job of your dreams!

  1. Ask questions about the problem to clarify it.
  2. Don’t jump into the code, think and discuss.
  3. Don’t stay muted for a while, clarify when you are thinking, “Can I think for a second?”.
  4. Think out loud.
  5. Multiply the examples.
  6. List the corner cases.
  7. Ask for approval before coding, “Does it seem like a good strategy ?” “Should I start coding ?”
  1. Can sorting input data help me ?
  2. Can splitting input data help me ?
  3. Can a dictionary help me ?
  4. Can multiple pointers help me ?
  5. Can a frequency array help me ?
  6. Can multiple pass help me ?
  7. Can case-based reasoning help me ?
  8. Is there an ends here/with property ?
  • Checking if $i in Stack$ in $O(1)$: just keep updated an “is_in” array is_in_stack where is_in_stack[i] tells whether $i in Stack$.
  • Sets with fewer than 64 possible items can be coded as integers.
  • For singly linked lists, creating 2 pointers $n$ nodes apart may be handy. It is also applicable to every sequence of elements. (find the middle / $n^{th}$ from the end, a cycle…)
  • Use infinite boundariesfloat('inf') ormath.inf.
  • Use frequency arrays when counting letters. A counting sort might also prove useful (as it is linear for frequencies) later on.
  • To find $a$ and $b$ in a array so that $a+b = c$, save every seen number in a set $S$ and for every new $i$, check if $c-i in S$.
  • sortedBisection search

  • iterative DFS ➜ stack

  • BFS ➜ queue

    • Need to keep track of the depth? → 2 queues
  • Optimal substructureDynamic programming to compute all the optimal solution of size $0 ldots n$ and deduce the solution.

    • when it is possible to craft the optimal solution for an instance size $n$ using the solution to instances of size $i_1, ldots, i_p < n$.
    • Can be on a pair of parameters, solution of size $(n, k)$ can be deduced from solution of size $(i, j)$ where $i leq n$ and $j leq k$.

    Examples: subarray, knapsack, longest substring

Do It Yourself

Solve an example with your brain and hands and see what “algorithm” you used.

B.U.D.

Bottlenecks, Unnecessary work, Duplicated workWalk through your best algorithm and look for these flaws.

Space/Time tradeoffs

Can I save time by using more space ?

  • Hash tables
  • Frequency arrays
  • Dynamic programming
  • Stack

    • $O(1)$: l = [], l.append(), l.pop(), l[i], len(l)
    • $O(n)$: del l[i], l[inf:sup:step]
    • $O(nlog_2(n))$: l.sort(), sorted(l)
  • Queue

    • $O(1)$: dq = deque(), dq.popleft() , dq.appendleft(x) + normal list operations except slices
  • Dictionary / Hashtable

    • $O(1)$: dic = {}, key in dic, dic[key], del dic[key] on average, worst case $O(n)$
  • Set

    • $O(1)$: s = set([]), x in s, s.add(x), del s[x]
    • $O(n_1)$: s1 s2 , s1&s2 , s1-s2, s1^s2
  • Heap / Priority Queue

    • $O(1)$: h = []
    • $O(log_2(n))$: heappush(h, x), heappop(h)
    • $O(nlog_2(n) )$: heap = heapfy([1, 5, 2, 3...])
    • left = 2*i; right = left+1; father = i//2 if h[0] in a 1-based array
    • left = 2*i+1; right = 2*i+2; father = depends on parity otherwise
  • Union find

    • to be continued

Bisection search ends when left and right cross.

Python Cheat Sheet Download

When will they cross ?

  • f(x, key) = x < key ➜ Move right when x key
    • Index of the first occurrence of key
  • f(x, key) = x <= key ➜ Move left when x key
    • Index of the last occurrence of key + 1
  • Might be necessary to check if the final value points to key

Merge sort

  1. Split the list in 2
  2. Recursively sort the left-most part and right-most part
  3. Merges these parts

Counting sort

Coding Interview Cheat Sheet Python

Python Coding Questions Interview

  1. Count the occurences of each possible values
  2. Put the number of occurence times each value in the array, starting from the smallest one

Simple steps

  1. Recursive solution
  2. Store intermediate results
  3. Bottom up (Optional)
  • Consider adding dummy values because things like res[x][y] may throw index errors on corner cases.
  • It can be easier to find the size of the best solution and then backtrack to find the solution.

Recursive solution

Memoization

@lru_cache(maxsize=None) can automate the memoization process by using a dictionary to store the result of function calls (less efficient than an array).

Bottom up

Operation

  • x << y Returns x with the bits shifted to the left by y places (and new bits on the right-hand-side are zeros). This is the same as multiplying x by 2**y.

  • x >> y Returns x with the bits shifted to the right by y places. This is the same as //‘ing x by 2**y.

  • x & y Does a “bitwise and”. Each bit of the output is 1 if the corresponding bit of x AND of y is 1, otherwise it’s 0. Commutative and Associative.

  • x y Does a “bitwise or”. Each bit of the output is 0 if the corresponding bit of x AND of y is 0, otherwise it’s 1. Commutative and Associative.

  • ~ x Returns the complement of x - the number you get by switching each 1 for a 0 and each 0 for a 1. This is the same as -x - 1.

  • x ^ y Does a “bitwise exclusive or”. Each bit of the output is the same as the corresponding bit in x if that bit in y is 0, and it’s the complement of the bit in x if that bit in y is 1. Commutative and Associative.

Coding sets on bits

Efficient when there is less than 64 possible values

SetBinary
$emptyset$0
${i}$1 << i
${0, 1, ldots, n-1}$(1 << n) - 1
$A cup B$`A
$A cap B$A & B
$(A setminus B) cup (B setminus A)$A ^ B
$A subseteq B$A & B A
$i in A$(1 << i) & A
${min(A)}$-A & A

You should ideally now about:

(Most are overkill for an interview but nice to know as a software engineer)

Numeric/mathematical

  • Kadane’s algorithm (maximum subarray)
    • every subarray has an ending
    • the maximum subarray ending at the spot i + 1 is either
      1. maximum subarray ending at the spot i + A[i + 1]
      2. A[i + 1]
  • Boyer-Moore majority vote algorithm
    • find a candidate for the majority element
      1. keep a counter of the number of occurence of the current candidate while iterating through the list
      2. ++ if the current element is the candidate -- otherwise
      3. if counter reaches 0, candidate = current candidate
    • check if the candidate is the majority element
  • Quickselect / Median-of-medians
  • Reservoir sampling
  • Sieve of Eratosthenes
  • Alias method
  • Euclid’s algorithm
    • if b != 1 return = gcd(b, a % b)
    • else return a
  • Exponentiation by squaringMatrix exponentiation
    • Just square exponentiation with matrix
    • res = res * a if n odd
    • a = a * a otherwise
  • Matrix exponentiation
    • use exponentiation by squaring
  • Range minimum query

Tree/graph

  • BFS
    • stack or recursion
  • DFS
    • queue
  • Dijkstra’s algorithm
  • A* search
  • Toposort
  • Morris traversal
  • Prim’s algorithm
  • Kruskal’s algorithm
  • Bellman-Ford algorithm
  • Graham scan algorithm
  • Ford-Fulkerson algorithm / Edmunds-Karp algorithm
  • Floyd’s cycle finding algorithm
  • Closest pair of points algorithm
  • Hopcroft-Karp algorithm

String

  • Longest common subsequence
    • lcs[p][q] = lcs ending at index p in str1 and q in str2 (DP)
    • lcs[p][q] = str1[p] str2[q] ? 1 + lcs[p-1][q-1] : max(lcs[p][q-1], lcs[p-1][q])
  • Rabin-Karp algorithm
  • Knuth-Morris-Pratt algorithm
  • Aho-Corasick algorithm
  • Ukkonen’s algorithm / SA-IS algorithm
  • Manacher’s algorithm

Search

  • Interpolation search
  • Meta binary search

Sorting

  • Heap sort
  • Quicksort + Three way partitioning + Median of three
  • Dutch national flag algorithm

Other

  • Fisher-Yates shuffle
  • Shunting-yard algorithm
  • Minimax
  • Mo’s algorithm
  • Square root decomposition
  • Rolling hash
  • Questions about the stack, the tests, the integration process, documentation of production incidents…

  • Standard dev environment ? Mandatory ?

  • What are the weekly meetings ?

  • What’s the remote policy ?

  • What’s the product schedule and deployment frequency ?

  • What about conference/event attending ?

  • Is there any dedicated time for self-training ? Contributing to FOSS ?

  • What does it take to be successful here ?

To evaluate the global software engineering quality using the joel (StackOverflow co-founder) test:

  1. Do you use source control?
  2. Can you make a build in one step?
  3. Do you make daily builds?
  4. Do you have a bug database?
  5. Do you fix bugs before writing new code?
  6. Do you have an up-to-date schedule?
  7. Do you have a spec?
  8. Do programmers have quiet working conditions?
  9. Do you use the best tools money can buy?
  10. Do you have testers?
  11. Do new candidates write code during their interview?
  12. Do you do hallway usability testing?