[JAVA] easy explained solution
\'\'\'public int[] maxSubsequence(int[] nums, int k) {\n\n    int ans[] = new int[k];\n\t\n\t//get the k largest integers in priority queue\n    PriorityQueue p
\'\'\'public int[] maxSubsequence(int[] nums, int k) {\n\n    int ans[] = new int[k];\n\t\n\t//get the k largest integers in priority queue\n    PriorityQueue<Integer> pq = new PriorityQueue<>();\n\n\tfor(int i=0; i<nums.length; i++){\n\t\tpq.add(nums[i]);\n\n\t\tif(i>=k) pq.poll();\n\t}\n    \n\t//store elements present in queue in hashmap\n    HashMap<Integer, Integer> map = new HashMap<>();\n    \n    for(int i=0; i<k; i++){\n        int a = pq.poll();\n        map.put(a, map.getOrDefault(a, 0)+1);\n    }\n    \n\t//to check values\n    //System.out.println("New HashMap: " + map.toString());\n    //add the values in result array in the right order\n    int l=0;\n    for(int j=0; j<nums.length; j++){\n        if(l==k) break;\n        \n        if(map.containsKey(nums[j])){\n            ans[l] = nums[j];\n            l++;\n            int f = map.get(nums[j])-1;\n            if(f>=1)\n                map.replace(nums[j],f);\n            else if(f == 0)\n                map.remove(nums[j]);\n        }\n            \n    }\n    \n\treturn ans;\n}
['Heap (Priority Queue)', 'Java']