Last reviewed
Correct answer: B. Using two indices moving through an array, often from opposite ends or at different speeds
Explanation
Two pointers is a shape rather than a specific algorithm. You hold two indices into one sequence and advance them under a rule that guarantees progress, so the pair covers the whole input in a single linear pass where a brute-force search would need nested loops. The opposite-ends form handles palindrome checks, reversing in place and the two-sum scan on a sorted array. The different-speeds form gives you cycle detection and the fast-slow midpoint trick.
What makes it cheap is the data structure underneath. NIST defines an array as an assemblage of items randomly accessible by integers, the index, so moving an index is arithmetic, not traversal. The extra memory is two integers, which meets the in-place standard NIST states for sorting: at most a constant number of items are kept in auxiliary memory at any time. Linear time, constant space.
The other options name unrelated operations. Deleting an array is a free or a reassignment. Converting a string to a number is a parse, one cursor moving left to right. Sorting without comparisons describes counting or radix sort, which key on values rather than converging indices.
Sources
“An assemblage of items that are randomly accessible by integers, the index.”
“at most a constant number of items are kept in auxiliary memory at any time”
“Strings implement all of the common sequence operations, along with the additional methods described below.”
Practise 3 questions on this topic
Take Arrays & Strings — Timed Test (3 questions) — scored instantly, explanation for every question, no login.