• Courses
  • Tutorials
  • Practice
  • Contests
Switch to Dark Mode

DSA Tutorial - Two Pointer Technique: Question 1

Last Updated : Feb 12, 2025
Discuss
Comments

what will be the position of the pointers left, right after executing the above code?

C++
#include <iostream>
#include <vector>
using namespace std;

int main() {
    vector<int> arr = {1, 2, 3, 4, 5};
    int left = 0, right = 4;
    
    while (arr[left] < arr[right]) {
        left++;
        right--;
    }

    return 0;
}
C Java Python JavaScript



A

2, 2

B

2, 1

C

3, 2

D

2, 3

Tags:
Share your thoughts in the comments