int LargButMinFreq(int arr[], int n) { // code here priority_queue<int> pq; for(int i = 0; i < n ; i++){ pq.push(arr[i]); } int ans = 0,minFreq = INT_MAX; while(!pq.empty()){ int val = pq.top(),freq = 1; pq.pop(); while(!pq.empty() && pq.top() == val){ pq.pop() , freq++; } if(freq < minFreq) minFreq = freq, ans = val; } return ans; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter