Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:

  1. Only one letter can be changed at a time
  2. Each intermediate word must exist in the word list

For example,

g0d2 發表在 痞客邦 留言(0) 人氣()

A permutation, also called an “arrangement number” or “order,” is a rearrangement of the elements of an ordered list S into a one-to-one correspondence with S itself. A string of length n has n! permutation.
Source: Mathword(http://mathworld.wolfram.com/Permutation.html)

g0d2 發表在 痞客邦 留言(0) 人氣()

A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

g0d2 發表在 痞客邦 留言(0) 人氣()

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?

g0d2 發表在 痞客邦 留言(0) 人氣()

 

2016(1-3月) 

g0d2 發表在 痞客邦 留言(0) 人氣()

2016(1-3月) 


电面一轮
* reverse linked list.鏈枃鍘熷垱鑷�1point3acres璁哄潧
* implement circular array

Onsite 四轮
Round 1:
* group anagram
* phone number combination. 涓€浜�-涓夊垎-鍦帮紝鐙鍙戝竷

Round 2:
* check big/small endian. 鍥磋鎴戜滑@1point 3 acres
* move zero to right
* sparse vector storage and product

Round 3: Design post search

Round 4: research. 涓€浜�-涓夊垎-鍦帮紝鐙鍙戝竷

g0d2 發表在 痞客邦 留言(0) 人氣()

Given a binary tree, find its maximum depth.

The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

文章標籤

g0d2 發表在 痞客邦 留言(0) 人氣()

Given a binary tree, determine if it is a valid binary search tree (BST).

Assume a BST is defined as follows:

文章標籤

g0d2 發表在 痞客邦 留言(0) 人氣()

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.


# Definition for a point.

文章標籤

g0d2 發表在 痞客邦 留言(0) 人氣()

Fill in the missing code:

def print_directory_contents(sPath):
    """
    This function takes the name of a directory 
    and prints out the paths files within that 
    directory as well as any files contained in 
    contained directories. 

    This function is similar to os.walk. Please don't
    use os.walk in your answer. We are interested in your 
    ability to work with nested structures. 
    """
    fill_this_in

Answer

def print_directory_contents(sPath):
    import os                                       
    for sChild in os.listdir(sPath):                
        sChildPath = os.path.join(sPath,sChild)
        if os.path.isdir(sChildPath):
            print_directory_contents(sChildPath)
        else:
            print(sChildPath)

Example 6.18. Listing Directories

>>> os.listdir("c:\\music\\_singles\\")              1
['a_time_long_forgotten_con.mp3', 'hellraiser.mp3',
'kairo.mp3', 'long_way_home1.mp3', 'sidewinder.mp3', 
'spinning.mp3']
>>> dirname = "c:\\"
>>> os.listdir(dirname)                              2
['AUTOEXEC.BAT', 'boot.ini', 'CONFIG.SYS', 'cygwin',
'docbook', 'Documents and Settings', 'Incoming', 'Inetpub', 'IO.SYS',
'MSDOS.SYS', 'Music', 'NTDETECT.COM', 'ntldr', 'pagefile.sys',
'Program Files', 'Python20', 'RECYCLER',
'System Volume Information', 'TEMP', 'WINNT']
>>> [f for f in os.listdir(dirname)
...     if os.path.isfile(os.path.join(dirname, f))] 3
['AUTOEXEC.BAT', 'boot.ini', 'CONFIG.SYS', 'IO.SYS', 'MSDOS.SYS',
'NTDETECT.COM', 'ntldr', 'pagefile.sys']
>>> [f for f in os.listdir(dirname)
...     if os.path.isdir(os.path.join(dirname, f))]  4
['cygwin', 'docbook', 'Documents and Settings', 'Incoming',
'Inetpub', 'Music', 'Program Files', 'Python20', 'RECYCLER',
'System Volume Information', 'TEMP', 'WINNT']
1 The listdir function takes a pathname and returns a list of the contents of the directory.
2 listdir returns both files and folders, with no indication of which is which.
3 You can use list filtering and the isfile function of the os.path module to separate the files from the folders. isfile takes a pathname and returns 1 if the path represents a file, and 0 otherwise. Here you're using os.path.join to ensure a full pathname, but isfile also works with a partial path, relative to the current working directory. You can use os.getcwd() to get the current working directory.
4 os.path also has a isdir function which returns 1 if the path represents a directory, and 0 otherwise. You can use this to get a list of the subdirectories within a directory.

g0d2 發表在 痞客邦 留言(0) 人氣()

«12 3