Consider the following


#1
  1. j is initialized outside the loop.
  2. There is only one array.(and assume its sorted.)
    I guess these statements can help you realize something. although i think only the 1st statement is enough to solve this problem.