Amazon

Saturday, February 2, 2008

Algorithm interview questions

[1] Find a linear (O(n) in time) algorithm which does in-place
riffle shuffle of an array of size 2n.

[2] Write a program to check for balanced brackets (and braces, and parentheses)
without using a stack.
"{[]()" false.
"{[]()}" true.
")))(((" false
"((()))" true
"{}([]())" true
"[(]){}" false
Use O(n) time and O(1) space.

Wednesday, January 30, 2008

A probabalility question

You have N balls with N different colors. Randomly you draw two at a time,
then painting the first ball to match the second. What is the expected
number of drawings before all balls are the same color?

Tuesday, January 15, 2008

Python tips and tricks

Q: How to add current path into system?
A: sys.path.append(os.path.abspath('./'))