fixed typo in array index. rectification to diff algo.