Dynamic Programming, Facebook Coding Interview, Google Coding Interview, Coding Interviews, Java.
frequency[i] represent search frequency of value at i index. Dp state dp[i][j] represents minimum cost of search for elements from index i to j dp[i][i] = frequency[i] // Another example of diagonally aligned dp state len = 2 to s.length i = 0 to s.length - len j = i+len-1 dp[i][j] = for k in i to