Java Easy Solution | o(nlogn) Time Complexity | Priority Queue
The efficient way to retrieve the max from array is to use a max heap, which in Java is a PriorityQueue (min heap) with a reverse comparator.\n\n Follow 4 Easy 
The efficient way to retrieve the max from array is to use a max heap, which in Java is a PriorityQueue (min heap) with a reverse comparator.\n\n Follow 4 Easy steps-\n**Step1** : Create a max priority queue.\n**Step2** : Add all the elements to queue.\n**Step3** : Remove two max element at a time, find the difference and then add into the queue.\n**Step4** : Check if queue is empty return 0, else return the element\n\n\n```\n    public int lastStoneWeight(int[] stones) {\n        \n        // Create a max priority queue         \n        PriorityQueue<Integer> queue = new PriorityQueue<>(Collections.reverseOrder());\n        \n        // Add all the elements to queue        \n        for(int i : stones) {\n        \tqueue.add(i);\n        }\n        \n        // Remove two max element at a time, find the difference and then add into the queue         \n        while(queue.size() > 1) {\n            int num1 = queue.poll();\n            int num2 = queue.poll();\n            int num = num1 - num2;\n            queue.add(num);\n        }\n        \n        // Check if queue is empty return 0, else return the element         \n        if(queue.isEmpty()) {\n        \treturn 0;\n        }\n        return queue.poll();\n    }\n```\n\nTime Complexity - ```o(nlogn)```\nSpace Complexity - ```o(n)```
[]