I have a doubt in a answer

i am sending the answer , the question is written in answer at the top, please explain the part of code which i mentioned in my answer i want to know why we add n and the use %n in my solution,

its a humble request to you, solve this question on pen paper and explain how it is running dry run , each and every step of this code kindly explain and send me pick of the dry run of this program, and explain why we add n and then modulo by n ?? okkkkkk please reply as soon as possible here is the link https://ide.codingblocks.com/s/330691

Suppose you want to know the value of -2 % 5, (which is nothing but 3).
So, as to evaluate this we may write -2%5=(5+(-2))%5
Thus it is a safe practice to add n before taking mod.

i am getting the wrong answer if i remove this n and modulo will you please explain how we are traversing in this array , starting point and end point please clear me , its too confusing , i am not getting this, if you can share a pic with me of dry run of this code it will help me a lot

if(l == (r - 1 + n) % n) return cnt; how this works r is on the left side of l is on the right because r is i and l is i+1 , so by decrementing r which was already on the left how this satisfy that we are checking that they cross each other , hope so you are getting my point what i want to convey ,

// If current pair sum is less, move to // the higher sum side. else if (arr[l] + arr[r] < x) l = (l + 1) % n; IN THIS WHY WE WRITE L =( L+1) %N WHY WE DONT WRITE SIMPLY L+1 WHY % N USE HERE ??? FOR MORE CHECK MY CODE, IF IT IS CONFUSING , PLEASE SEND ME A DRY RUN OF THIS CODE ON PAPER , OR SEND ME ANY VIDE WHICH EXPLAIN WHY WE ARE WRITTING LIKE THIS, I WANT TO KNOW THIS ANSWER IN DETAIL

Can you share the link to the exact question you’re trying to solve?

this is the linkhttps://www.geeksforgeeks.org/given-a-sorted-and-rotated-array-find-if-there-is-a-pair-with-a-given-sum/ now please explain what i wnt to know,please in detail with dry run and send me image of dry run or whatever , elaborate as much as you can

.
The left and right pointers are moving in a way that. the array acts as a simple sorted array.

sir thankyou so much for this imAGE THIS HELPS ME ALOT , SIR jo aapne break ki condition mention kri h, hume kaise pta chl rha h ki tbhi loop break krna h hume ? l==(r-1+n)%n y satisfy ho gai thi islie count ki valu 2 return ho gai, but y condition hi ku li,?? matlb jo r he wo pura ek round laga kr l pr a gya islie ?? bs ye bta dijie pls sir and thankyou so much for sending me this pick thanks :slight_smile:

humne isme sare ements ko ony 1 time check kra ya fir islie , wo break ki condition li, ,

sorry woryt wali condition likh di thi glti se, thanks, for best explanation, thanks a lot