Commit 52b19bb
committed
feat: Add two-pointer method to reverse an array in-place
🧠 Logic:
- Introduced `ReverseTheArray(int[] arr)` method using two pointers (`p1` at start, `p2` at end).
- Swap elements at `p1` and `p2` and move both pointers towards the center.
- This reverses the array efficiently in O(n) time and O(1) space.
Signed-off-by: Somesh diwan <[email protected]>1 parent 2dc978c commit 52b19bb
1 file changed
+3
-4
lines changedLines changed: 3 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
4 | 3 | | |
5 | 4 | | |
6 | | - | |
7 | | - | |
| 5 | + | |
| 6 | + | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
0 commit comments