Sunday, January 30, 2022

Calculate mid value in indexes/number

If value of start and end are max. range of integer. 
So, by adding these 2 it will give Exception: java: integer number too large.

Hence, using 2nd approach this problem will not come.

// avoid using below thing
int mid = (start + end) / 2;

// correct approach
int mid = start + ((end - start) / 2);


No comments:

Post a Comment

Popular Posts

Most Featured Post

GitHub: Squash all commits in PR

  Command Meaning git fetch origin Get the latest origin/master . git reset --soft origin/master Move your branch to match origin/master , b...