Pair sum in a sorted array
one step at a time.
Start at both ends: if the sum is too big move r left, if too small move l right, and each move rules one number out for good.
Free to use. Step forward and back at your pace, and share a link to the exact step you are stuck on.
What you actually watch.
The part a dry run on paper loses: the state, at every step.
Start at both ends: if the sum is too big move r left, if too small move l right, and each move rules one number out for good. That sentence is easy to agree with and hard to hold in your head on step nine, which is where most people lose the thread.
So the visualiser keeps it in front of you: both indexes walking, and the span they have already ruled out. The line of code being executed is highlighted as the picture changes, so the drawing and the code never drift apart. Step forward, step back, or let it play.
Put your own input in. Pair sum in a sorted array on a clean example teaches you the shape; pair sum in a sorted array on an empty input, a single element, or one with duplicates teaches you the thing an interviewer asks about.
How it runs, step by step.
The same order the visualiser moves in, so the list and the picture match.
- 1Start one index at each end of the data.
- 2Compare what the two ends hold and decide which one can never improve.
- 3Move that pointer inward, which rules out everything it passed.
- 4Stop when the pointers meet: every possibility has been ruled in or out.
Where people get this one wrong.
These are not made up. Each one is a switch in the tool: turn it on, run the same input, and watch the state go wrong.
- Brute force: every pairIgnores the sorting and tries every pair: about n²/2 checks instead of n − 1.
- Bug: move both pointersAfter a miss it moves l and r together, dropping a number nobody proved useless. Try "Partner skipped".
Inputs worth trying.
The cases that teach something. Each one is a preset in the tool, with the reason it is there.
- Partner skippedRun the move-both bug here: it drops 1 while its partner 6 is still inside.
- No pairEven numbers, odd target: no pair, yet every step still rules one number out.
- Unsorted inputIt is sorted first, so the indexes are positions in the sorted array.
What it costs.
The two numbers an interviewer will ask for, and what they mean here.
- Time
- O(n)counted as real operations while it runs, not quoted from a table
- Space
- O(1)what the algorithm holds besides the input itself
- Pattern
- Two pointersTwo indexes walk towards each other, each step ruling something out.
Once you can see it, go and use it.
Watching is the first ten minutes. The pattern sticks when you solve with it.
Everything in the app, in one place.
Practice, interviews and the tools, all free to start. Swipe to see the rest.
DSA practice
Problems filed under the pattern that solves them, not a sheet.
352 problemsOpenCompany sets
Practise what one company actually asks, the week before the round.
463 companiesOpenCoding interview
Pick the role, write in a real editor, and answer while you type.
scored reportOpenMock interviews, spoken
You answer out loud, it follows up on what you said.
36 topicsOpenDatabase round
DBMS asked the way a panel asks it: indexes, joins, normal forms.
in Core CSOpenOOP round
Inheritance, polymorphism and the follow-up you never rehearse.
in Core CSOpenSystem design
How real systems are built, from the primitives to the AI stack.
27 chaptersOpenSQL practice
Real schemas, your query, the rows it returns, and an honest verdict.
39 questionsOpenAptitude
Quant, logical, verbal, DI and technical, timed like the real test.
280 questionsOpenOnline assessment
A clock, marks per question and hidden tests, like a company's judge.
37 papersOpenAlgorithm visualiser
Watch it run on your own input, one step at a time.
26 algorithmsOpenAI that helps, not solves
Hints one at a time, AI review before a mentor reads it.
100 free creditsOpenResume builder
Build it inside the app, next to the work you practised.
in the appOpenProgress and readiness
One score, and the axis you are weakest on.
tracked dailyOpen
Free to start: 100 AI credits when you sign up and 100 every month. Start free in the app
About pair sum in a sorted array.
Open it in the app and the answers are easier to see than to read.
Open the visualiserWhat does the pair sum in a sorted array visualiser show?
Every step of the algorithm on input you choose: both indexes walking, and the span they have already ruled out, with the line of code being executed highlighted beside it. You can step forward, step back, or let it play. Spelled visualizer or visualiser, it is the same tool.
What is the time complexity of pair sum in a sorted array?
O(n) time and O(1) space. The visualiser counts the real operations as it runs, so you can watch the number grow instead of taking the formula on trust.
Why does my pair sum in a sorted array code fail on some inputs?
Usually one of the known traps. The visualiser ships the real ones for this algorithm (move both pointers), so you can switch the bug on, run it, and watch exactly where the state goes wrong.
Can I use my own input?
Yes. Type your own array, string or graph and the algorithm runs on that, including the edge cases that break a solution in an interview.
Is it free?
Yes. The app is free to start, with 100 AI credits when you sign up and 100 every month, and watching an algorithm costs no credits.