/Python-Interview-Examples

This repo consist of Python Interview Examples

Primary LanguagePython

Python-Interview-Examples

Problem Statements

KthGrammer.py

On the first row, we write a 0. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10. Given row N and index K, return the K-th indexed symbol in row N. (The values of K are 1-indexed.) (1 indexed).

SortSubstring.py

Sort substrings

addOnetoNumber.py

Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit. You may assume the integer does not contain any leading zero, except the number 0 itself.

antiDiagonal.py

Given a matrix, return all elements of the matrix in antidiagonal order

breathFirstSearch.py

BreadthFirstSearch

breathFirstSearchShortestPath.py

breathFirstSearchShortestPath

climbingStairs.py

You are climbing a stair case. It takes n steps to reach to the top.

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

depthFirstSearch.py

DepthFirstSearch

fizzbuzz.py

Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.

isPower2.py

Given an integer, write a function to determine if it is a power of two.

maxOnes.py

Given a binary array, find the maximum number of consecutive 1s in this array.

maxSumContiguousSubarray.py

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

mergeSort.py

MergeSort

minSubArrayLen.py

Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead.

moveZerosToEnd.py

Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.

patternString.py

Find all the occurence of pattern string in an input string

permutationsPalindrome.py

Given a string, determine if a permutation of the string could form a palindrome.

permutationsString.py

Check if two string are permutations with each other

prisonAfterNDays.py

There are 8 prison cells in a row, and each cell is either occupied or vacant.

Each day, whether the cell is occupied or vacant changes according to the following rules:

If a cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied. Otherwise, it becomes vacant. (Note that because the prison is a row, the first and the last cells in the row can't have two adjacent neighbors.)

We describe the current state of the prison in the following way: cells[i] == 1 if the i-th cell is occupied, else cells[i] == 0.

Given the initial state of the prison, return the state of the prison after N days (and N such changes described above.)

quickSort.py

QuickSort

removeDuplicates.py

Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

reverseWords.py

Given an input string, reverse the string word by word.

setMatrixZeros.py

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.

stringCompression.py

Given an array of characters, compress it in-place.

The length after compression must always be smaller than or equal to the original array.

Every element of the array should be a character (not int) of length 1.

After you are done modifying the input array in-place, return the new length of the array.