check DistinctSub for dp solution
  it is tricky on nextRightPointer