Wednesday, December 27, 2017

Frequent Interview questions

=====================================================================
LC1TwoSum----------------------------
LC12IntegerToRoman.
LC13RomanToInteger
LC20ValidParentheses----------------
LC21MergeTwoSortedLists. -------------------
LC33SearchRotatedSortedArray---------
LC34Search for a range-----------
LC46PermutationI-------------------
LC47PermutationII---------------
LC50Powerxn-----------
LC53MaximumSubarray-------------------
LC56MergeIntervals---------------------
LC65ValidNumber高频---------------------
LC69SqrtX------------
LC76Min Window SubString-------------------------
LC77Combinations----------------
LC81SearchRotatedSortedArrayII------------------------
LC88MergeSortedArray--------------
LC90SubSetsII---------------------
LC100SameTree--------------------
LC102BinaryTreeLevelOrderTraversal-------------
LC103ZigZag--------------
LC127WordLadder-------------------
LC126WordLadderII-----------------------
LC149MaxPointsInaLine---------
LC150EvaluateReversePolishNotation---------
LC151ReverseWordInAString------------------
LC152MaximumProductSubarray-----------------------
LC156BinaryTreeUpsideDown-------------------
LC160IntersectionTwoLinkedLists. & Union-------------------
LC170TwoSumIII-------------
LC173BinarySearchTreeIterator----------------
LC186ReverseWordsStringII-----------------
LC187RepeatedDNASequences-------------------
LC189RotateArray-------------
LC199BinaryTreeRightSideView----------
LC200 number of islands--------------
LC205IsomorphicStrings------------------
LC215KthLargestArray--------
LC235LowestCommonAncestorBinaryTree-------
LC236LowestCommonAncestorII-----------------
LC243ShortestWordDistance------------
LC244ShortestWordDistanceII----------
LC245ShortestWordDistanceIII-----------
LC254MyFactors----------------------
LC266PalindromePermutation-------------------
LC267------------------------
LC277FindCelebrity--------------
LC297Serilize & deserilize
LC339SumNestedList----------------
LC347TopKFrequentElements--------------
LC364 Nested SumII----------------
LC366PrintTreeLeaf-------------------
LC380InsertDeleteGetRandomI----------------
LC381InsertDeleteGetRandomII---------------
LC409LongestPalindrome------------------------------
LC534TinyURL------------------
LC605Can place flower-------------------------
BoundedBlockingQueue------------------------
GenericClass
LinkedListSingle2Double
MaximumDepth BT----------------------
实现一个hash table,get, put, 最后在加一个resize-----------------


============================================
MaximumIntervalsOverlap
Coding: Maximum number of overlapping intervals
For example – { (0,2), (3, 7), (4,6), (7,8), (1,5) }. The maximum number of intervals overlapped is 3 during (4,5).
===========================================
MultiSum
KNearestPoints2D

QuickSort

RightRotateTree

ThreeClosestElements

Triangle

TriangleII

convert bst to doubly linked list

binary tree to n-ary tree

maximum palindrome subarray
===================

题目: Given一个array of non-negative integers, 找出3组数字可以组成3角形, 每个数字表示边长, 组成3角形的充要条件就是任2边的和要大于第3边 答案: 对这个array做sorting后, 从array的最小的element开始往最大去扫, 以连续3个数字一组确认是否可以构成3角形
====================



一棵树有不限个数的子节点,有多层节点,不规则分布。给定子节点数K,重构这棵树。比如,子节点数是3。那么第一层是1个节点,第二层是3个节点,因为root最多有可以有三个节点。第三层是9个节点,因为第二层的三
===============================


2)retainBestCache,设计一个cache,他给你一个getRank()的方法,当cache满了的时候,要把rank最低的移除,开始以为是LRU Cache,结果发现不是,稍微有点慌,卡住了,说用arraylist来存,说完发现好蠢,每次移除都得O(n)来找rank最低的,然后他提示我还可以更高效,我一下子就想到了PriorityQueue,面完了发现确实该用PriorityQueue,可惜没完全写完,把comparator什么的写完了,但是写得很乱
写一个RetainBestCache的数据结构,给定了getRank函可以直接用来得到当前cache的rank,然后有capacity的限制,当达到capacity的时候要拿出当前所存lowest rank的cache,跟新的cache比较,保留rank较高的那个
================================================


第二题:design a max stack that supports all regular stack operations and peekMax popMax in log time
让你设计一个MaxStack,要求实现以下功能。
class MaxStack {
    int Pop(); // Pop the value on top of the stack;
    void Push(int); // Push a new value into the stack;
    int Peek(); // Return the value on top of the stack;
    int PopMax(); // Pop the max value in the stack; logN
    int PeekMax(); // Return the max value in the stack;logN
}
===============================================================

Build a tree given a list of relationship (parent -> child, 以及一个boolean isLeft)。
用一个hashmap做的。