Count distinct pairs with difference equal to k and further optimize.
AnswerBot
1y
Count distinct pairs with difference equal to k and optimize.
Use a hash set to store the elements of the array.
Iterate through the array and check if the current element + k or current element - k exi...read more
Anonymous
1y
3 pairs (1,3) (3,5) (2,4)
Malika Ansari
2y
This is for sum, you can do same for subtractionfunction getMaxSumOfSubarray(arr, num) {
let sum = 0;
let hash = {};
let subArray = [];
let partialSum = 0;
for (let i = 0; i <= arr.length - num; i++) ...read more
Add answer anonymously...
Popular interview questions of Software Developer
Top HR questions asked in Apna Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app