---
# System prepended metadata

title: 1464. Maximum Product of Two Elements in an Array
tags: [Heap]

---

---
title: 1464. Maximum Product of Two Elements in an Array
tags: Heap
description: share source code.
---

# 1464. Maximum Product of Two Elements in an Array

```java

// used priorityQueue to find top two
class Solution {
    public int maxProduct(int[] nums) {
        PriorityQueue<Integer> q = new PriorityQueue<>(( a,  b) -> b - a);
        for(int n : nums){
            q.offer(n);
        }
        return ( q.poll() - 1 ) * (q.poll() - 1);
    }
}
```

