Dsa
Two Pointers
Medium
Adjacent Sum Pairs
You are given an integer array nums. Your task is to count the number of pairs of adjacent elements in the array whose sum is equal to a given value k. Return the count.
Input:
The first line contains two integers n (1 <= n <= 1000) and k,
The second line contains n integers, the elements of nums.
Output:
An integer representing the number of adjacent pairs with the sum equal to k.
Example:
Input:
5 6
1 2 3 4 2
Output:
2
Explanation: The adjacent pairs (2, 4) and (4, 2) sum up to 6.
Key concepts
two_pointersarraysum
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now