Skip to content

Latest commit

 

History

History
149 lines (138 loc) · 10.1 KB

Technical-Interview-Questions-Set-1.md

File metadata and controls

149 lines (138 loc) · 10.1 KB

#Interview Questions This is a collection of some of the tough-easy questions which you might face in technical interview. ##General

  1. Find the most frequent integer in an array. Answer1 - O(n^2) / Answer2 - O(n)
  2. Find pairs in an integer array whose sum is equal to 10 (bonus: do it in linear time)
  3. Given 2 integer arrays, determine of the 2nd array is a rotated version of the 1st array. Ex. Original Array A={1,2,3,5,6,7,8} Rotated Array B={5,6,7,8,1,2,3}
  4. Write fibbonaci iteratively and recursively (bonus: use dynamic programming)
  5. Find the only element in an array that only occurs once.
  6. Find the common elements of 2 int arrays
  7. Implement binary search of a sorted array of integers
  8. Implement binary search in a rotated array (ex. {5,6,7,8,1,2,3})
  9. Use dynamic programming to find the first X prime numbers
  10. Write a function that prints out the binary form of an int Answer 1 / Answer 2 - Recursive
  11. Implement parseInt
  12. Implement squareroot function0
  13. Implement an exponent function (bonus: now try in log(n) time)
  14. Write a multiply function that multiples 2 integers without using *
  15. HARD: Given a function rand5() that returns a random int between 0 and 5, implement rand7()
  16. HARD: Given a 2D array of 1s and 0s, count the number of “islands of 1s” (e.g. groups of connecting 1s)

##Strings

  1. Find the first non-repeated character in a String
  2. Reverse a String iteratively and recursively
  3. Determine if 2 Strings are anagrams
  4. Check if String is a palindrome
  5. Check if a String is composed of all unique characters
  6. Determine if a String is an int or a double
  7. HARD: Find the shortest palindrome in a String
  8. HARD: Print all permutations of a String
  9. HARD: Given a single-line text String and a maximum width value, write the function ‘String justify(String text, int maxWidth)’ that formats the input text using full-justification, i.e., extra spaces on each line are equally distributed between the words; the first word on each line is flushed left and the last word on each line is flushed right

##Trees

  1. Implement a BST with insert and delete functions
  2. Print a tree using BFS and DFS
  3. Write a function that determines if a tree is a BST
  4. Find the smallest element in a BST
  5. Find the 2nd largest number in a BST
  6. Given a binary tree which is a sum tree (child nodes add to parent), write an algorithm to determine whether the tree is a valid sum tree
  7. Find the distance between 2 nodes in a BST and a normal binary tree
  8. Print the coordinates of every node in a binary tree, where root is 0,0
  9. Print a tree by levels
  10. Given a binary tree which is a sum tree, write an algorithm to determine whether the tree is a valid sum tree
  11. Given a tree, verify that it contains a subtree.
  12. HARD: Find the max distance between 2 nodes in a BST.
  13. HARD: Construct a BST given the pre-order and in-order traversal Strings

##Stack, Queue and Heaps

  1. Implement a stack with push and pop functions
  2. Implement a queue with queue and dequeue functions
  3. Find the minimum element in a stack in O(1) time
  4. Write a function that sorts a stack (bonus: sort the stack in place without extra memory)
  5. Implement a binary min heap. Turn it into a binary max heap
  6. HARD: Implement a queue using 2 stacks

##Linked List

  1. Implement a linked list (with insert and delete functions)
  2. Find the Nth element in a linked list
  3. Remove the Nth element of a linked list
  4. Check if a linked list has cycles
  5. Given a circular linked list, find the node at the beginning of the loop. Example: A →B →C → D →E →C, C is the node that begins the loop
  6. Check whether a link list is a palindrome

##Sorting

  1. Implement bubble sort
  2. Implement selection sort
  3. Implement insertion sort
  4. Implement merge sort
  5. Implement quick sort
  6. Reverse a linked list iteratively and recursively

##BSTs, Heaps, Search Algorithms, Sort Algorithms, Intersection, median, hashmap, caching system, basic algorithms

  1. Basic bitwise operations
  2. How do you program a min heap using Nodes
  3. Find the max value in an array. The array is "semi-sorted".

Ex. { 1 3 4 7 9 10 12 13 12 6 3 }

  1. Write a code that accepts integers as arrays and outputs the multiplication result as an array.
  2. Write a code that takes the coordinates of multiple rectangles as input and returns as output the coordinates of the rectangle that is the intersection of all the rectangles. Typical low level CS questions about sorting algorithms and operational cost.
  3. Median finding algorithm - find the median of 'n' numbers and a little bit of binary search tree implementation
  4. Find the largest rectangle with all 0s in an matrix with only 0 and 1.
  5. Convert char string to integer.
  6. Find occurrences of a number in sorted array (allow duplicates).
  7. If integer array used to store big integers (one integer store one digit), implement arithmetic operations.
  8. How to build a heap?
  9. What is the optimized version of the knn algorithm?
  10. Write a recursive function to calculate pascal's pyramid numbers. A question related to binary search, which is a kind of weak spot and I always avoid using it.
  11. Explain Singleton structure, how to create
  12. Given k sorted pivots, write procedure partition in quicksort
  13. Find the median of three numbers.
  14. Generate all balanced parentheses combinations of given length.
  15. The second question asked, how to find two missing integers in an unsorted array
  16. Given an array of characters in it, how would you reverse it?
  17. Write a program to comparing two array, one being very large
  18. To generate a fibonacci number sequence, and discuss its time and space complexity To merge two sorted integer arrays.
  19. Returning the n-th element of a linked list.
  20. How to randomly select a number with equal probability from an array with unknown size? Write an algorithm to find the 3rd highest number from an array of random integers
  21. Given a sorted array of n integers that has been rotated an unknown number of times, write code to find an element in the array. Sorted in increasing order Input: find 5 in (15, 16, 19, 20, 25, 1, 3, 4, 5, 6, 10, 14) Output 8
  22. Implement a simple regular expression matching function

##Other

  1. Given a max-heap, how do I find the top k items?
  2. Find the border length created from a conglomeration of various 2D rectangles.
  3. Write a minPeak function for a stack (function that returns the minimum element in the stack).
  4. Find the nth fib number
  5. Design a function in your favorite programming language to convert a camelCase string to all lowercase.
  6. Implement a hashset
  7. Given a corpus of valid words, design a function that takes a word as input and outputs all valid anagrams of that word.
  8. Given an input of a 3D matrix of ones and zeros, count the number of contiguous 1-filled regions (as separated by 0-filled regions), as well as the size of the largest one (I think; doesn't really change the problem much).
  9. You have two sets. How would you know that they converge.
  10. Given a bag of nuts and a bag of bolts, each having a different size within a bag but exactly one match in the other bag, give a fast algorithm to find all matches
  11. Preorder traversal without recursion
  12. Find the largest possible difference in an array of integers, such that the smaller integer occurs earlier in the array.
  13. How to find if n numbers in a list sum up to an integer k?
  14. Find largest palindrome in string
  15. Make an anagram solver that returns all valid dictionary words given a set of characters.
  16. Sort a string by the order it's characters appear in another string
  17. Given a value k and an array , design an efficient algorithm that should output the number of pairs that sum up to k.
  18. How do you find three numbers that sum to 0? (in a list). Now can you do it under O(n^3)?
  19. Given a Fibonacci number, tell us which index it occurs at.
  20. Describe an algorithm that would find n numbers in a list that sum to 0.
  21. Given an array of n unsorted ints, with the condition that each number is at most k positions away from its final sorted position, give an efficient sorting algorithm
  22. Give an efficient solution for subset sum.
  23. Given two (i,j) coordinates of a cell in two dimensional matrix. These coordinates are the lower left and upper right corner of a rectangle contained within the matrix. Sum all the elements in the matrix. Time and space?
  24. String has all unique characters
  25. Two strings to see if one is a permutation
  26. Remove dups from an unsorted linked list
  27. Find kth algorithm of singly linked list
  28. Delete a node in the middle of a singly linked list given access to that node
  29. Write code to partition a linked list around a value x such that all nodes less than x come before all nodes greater than or equal to x
  30. Single array to implement three stacks
  31. Stack with min element
  32. Towers of Hanoi
  33. Sort a stack in ascending order using at most one additional stack to hold items but you may not copy the elements into any other data structure
  34. Function to see if a tree is balanced
  35. Graph algorithm, route between two nodes
  36. Create bst from sorted array with minimal height
  37. Binary tree is a bst
  38. A child is running up a staircase with n steps, and cah hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways the child can run up the stairs
  39. Two sorted arrays, A has a large enough buffer at the end to hold B, merge B into A in sorted order
  40. Write a method to sort an array of strings so that all the anagrams are next to each other
  41. Find an element in a sorted array that has been rotated an unknown number of times
  42. Implement a method that returns true if the edit distance between two strings is less than 2 (1 or 0) or false otherwise
  43. Given two lists of chars, return the first with removed characters that appear in the second list.