Simple and Optimal Solution
IntuitionApproach
create a copy of array, so that the order is preserve in original array.
osrt the copy array.
put the top k elements into the hashMap, count t
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
1. create a copy of array, so that the order is preserve in original array.
2. osrt the copy array.
3. put the top k elements into the hashMap, count the frquency of the dublicate element and store it into the map. 
4. run a loop over the original array search for the element in map if reduce the count in map of that specific number, keep on filling the array.
5. return the result array

# Complexity
- Time complexity: O(nlogn) overall
<!-- Add your time complexity here, e.g. $$O(n)$$ -->


- Space complexity: O(n) overall
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int[] maxSubsequence(int[] nums, int k) {
        int[] copy = Arrays.copyOf(nums, nums.length);
        Arrays.sort(copy);
        int n = nums.length;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = n-1; i >= n-k; i--) {
            map.put(copy[i], map.getOrDefault(copy[i], 0)+1);
        }
        int[] arr = new int[k];
        int count = 0;
        for ( int i = 0; i < nums.length; i++) {
            if (count < k && map.containsKey(nums[i]) && map.get(nums[i]) > 0) {
                arr[count++] = nums[i];
                map.put(nums[i], map.get(nums[i])-1);
            }
        }
        return arr;
    }
}
```
['Array', 'Hash Table', 'Sorting', 'Java']