Computer Science, asked by sahanagchinnu1999, 8 months ago

Given an array of integers A, and an integer K find number of happy elements. Element X is happy if there exists at least 1 element whose difference is less than K i.e. an element X is happy, if there is another element in the range [X-K, X+K] other than X itself. Constraints 1 <= N <= 10^5 0 <= K <= 10^5 0 <= A[i] <= 10^9

Answers

Answered by mahalakshmi56
25

Answer:

jkabfzblapabzhbsb

Explanation:

bjnxbznhjzmBbz

Answered by vrundpatel99240
7

Answer:

Use TreeSet

Explanation:

My logic : 1st remove duplicates bcz duplicate are happy. Aur hum usko hashmap se remove karenge ( if there is frequency of element is 5 then we will remove those 4 elements and add count 4 in our answer)

2nd make Treeset for rest of the element.

Use treeset. Higher( x-k-1) if this is in the range of x+k. And at the end you have to see end cases well. Solution will be O(nlogn)

Similar questions
Math, 8 months ago