Place opposite-end pointers01.01
Opposite-end placement puts L at index 0 and R at index n-1 so the two indices face each other across the whole array. You name them from length. You do not scan to find the ends.
After placement, L = 0 and R = n-1, and L ≤ R. n = 1 lands both on the only cell.
Same skill, three traces. Read all three before you try it.
01three - given
a = [4, 1, 9]- walk
n = 3L←0,R←2a[0]=4facesa[2]=9- result
L=0,R=2
02four - given
a = [4, 1, 9, 1]- walk
n = 4L←0,R←3- result
L=0,R=3
03empty - given
a = []- walk
n = 0there is no index
0orn-1- result
- no
L,R
placeEnds(a).a is an array of integers. L is the left index. R is the right index.Set
L = 0 and R = n-1 when n ≥ 1. Print L and R after placement. On empty, print that there is no L or R.On
[4, 1, 9] print L=0, R=2. On [4, 1, 9, 1] print L=0, R=3. On [] print no L, R.constraintsa may be empty. When nonempty, length ≥ 1.
- Valid Palindrome0/3 skills ready · two pointers · easyopen
- Valid Palindrome0/3 skills ready · two pointers · easyopen
Every Check with Awel is frozen here. Open one to read the code or load it back into the editor.