bhaiya is question mai jese mera heap maanlo
A = { 128, 162 , 200 } hai , ab kth smallest nikaalne ke liye ek or priority queue lu or usme (k-1) elements daal du is queue ke or fir is queue mai se q.top() krke kth least element find out kru ??
yaa koi or approach?
HOSTEL VISIT QUESTION
hello @CODER_JATIN
approach sahi hai but iski time complexity jayda hogi.
hint-> max heap use kar ke isko less time me kar sakte hai
sahi to lag raha hai mujhe.
kya issue aa raha hai?
ek test case pass hua bs
use long long for x n y
thik hai bhaiya , done hai
, approach sahi hai ye?
ha . . . . . . . . . . . . .
bhaiya ye "top k frequent number wale question smjhana ek baar " , question ni smjh aaya vo
Whenever we input a number, we’ve to output k most frequent numbers in decreasing order, and if frequency of two or more numbers is same print them in increasing order, and if numbers present till now is less than k print all of them following the same criteria for frequency.
Let’s discuss the given example:
1
5 2
5 1 3 5 2
Here t = 1
for the given test case n = 5, k = 2
so let’s see what happend when each number is inputted:-
when the first number 5 is inputted, the numbers present are
5 with frequency 1,
so we only print 5
when 1 is inputted
the numbers present are
5 with frequency 1,
1 with frequency 1,
two numbers with same frequency present, so we output them in increasing order:
We print 1 5
when 3 is inputted,
the numbers present are
5 with frequency 1,
1 with frequency 1,
1 with frequency 1,
three numbers with same frequency present, so we output k of them in increasing order:
We print 1 3
when 5 is inputted
the numbers present are
5 with frequency 2,
1 with frequency 1,
1 with frequency 1,
highest freq is 2, and 2nd highest is 1(for 1, 3 but we can print only 2 numbers, and we’ve to print same frequency numbers In increasing order,
We print 5 1
When 2 is inputted:
the numbers present are
5 with frequency 2,
1 with frequency 1,
1 with frequency 1,
2 with frequency 1
highest freq is 2, and 2nd highest is 1(for 1, 2, 3 but we can print only 2 numbers, and we’ve to print same frequency numbers In increasing order,
We print 5 1
so printed numbers are
5 1 5 1 3 5 1 5 1
bhaiya , if numbers till now is less than k, then in which format we have to print?
on the basis of their frequency.
also bro create seprate thread for seprate doubt
okay bhaiya i’m creating separate thread , thank you
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.