Own code error. check

i wrote my own code. i shows wrong output. debug?

Okay @priyamthakuria27

Where is your code?

Hello @priyamthakuria27,

Mistakes in your code:

  1. Value of e.
    Correction:
    e = a[n - 1] - a[0]+1;

  2. The mid is not necessarily be the answer.
    Solution:
    Rather use a separate variable.

  3. Int datatype is not appropriate to satisfy the given constraints.

  4. Wrong initial value of the for loop.
    for (int i = 0; i < n; i++) {
    Correction:
    for (int i = 1; i < n; i++) {

Refer to the following code:

Hope, this would help.