3 Rounds phone interview...
#1. Given array A[], find A[j] - A[i] which is max and j < i
A: DP
#2. String reverse
#3. Implement a hash table
#4 Prefix calcuator
public class Stream { public String[] equation; public int index; public int length; public Stream(String eq) { this.equation = eq.split(" "); this.index = 0; this.length = equation.length; } public int getNum() { if (index < length) { return Integer.valueOf(equation[index++]); } return -9999999; } public String getOP() { if (index < length) { return equation[index++]; } return null; } public boolean hasNext() { return index < length; } public int getValue() { this.index = 0; int value = 0; int num = getNum(); while (hasNext()) { String op = getOP(); if (op.equals("+")) { value = value + num; num = getNum(); } else { // op == "*" num = num * getNum(); } } value = value + num; return value; } public static void main(String[] args) { Stream stream = new Stream("4 * 5 * 2 + 3"); System.out.print("value = " + stream.getValue()); } }