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...
Apna Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter