MAkeathon problem

There was question in American Expreess hackhathon that you are given an array of numbers ,now you need to return a subsequence of length k(k is a user input) such that it has the min number of distinct numbers…
Now what I did was to sort the array and count the occurence of the each and every num in that array and then ,the storing the index of that num whose occurence is max and then return k integers from that index…Was my approach correct because if subsequence is asked then its not necceassary to maintain the order…Please suggest me a best approach for this problem…

I thought it’s subarray. If it’s subsequence then you can apply dp in it.

Rest this sems good.


Same approach as you have mentioned.

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.