// BUILDING THIS WITH AN AI AGENT (2026)
Whether you are using Claude Code, Cursor, Windsurf, GitHub Copilot, Gemini Code Assist, Aider, or Cline — the productive pattern for production code in this space is: scaffold first, then ask for the idiomatic refactor. The prompt sequence:
Agents are good at idiomatic code when you explicitly ask — they default to older patterns otherwise.
Question :
Given an array of integers A, return the largest integer that only occurs once.
If no integer occurs once, return -1.
Example 1:
Input: [5,7,3,12,4,12,11,3,1]
Output: 11
Explanation:
The maximum integer in the array is 12 but it is repeated. The number 11 occurs only once, so it's the answer. Example 2:
Input: [9,9,8,8]
Output: -1
Explanation:
There is no number that occurs only once. Note:
1 <= A.length <= 20000 <= A[i] <= 1000Solution:
To find the largest unique number , first we will take an array of size 1001 as the note says the maximum array length would be 1000, we will loop through the given array and increase the index in the newly created array, once out pass through the array, we parse the newly created array from i=1000 to 0 and would return the first index of the array whose value is 1.
class Solution {
public int largestUniqueNumber(int[] A) {
int [] res = new int [1001];
for(int i = 0; i < A.length; i++){
res[A[i]]++;
}
for(int i = 1000; i >= 0; i--){
if(res[i] == 1){
return i;
}
}
return -1;
}
}
This is the Largest Unique Number Java Solution in the below post.
For the AI-native engineering side of HackerHeap — building MCP servers, comparing agents (Claude Code, Cursor, Windsurf, Codex, Gemini, Copilot), and weekly working code — see the Friday Build newsletter and the MCP archive.
HackerHeap is back: a multi-platform resource for working developers building with AI coding agents. We…
// SOLVING THIS WITH AN AI ASSISTANT (2026)If you are working through this problem with…
// SOLVING THIS WITH AN AI ASSISTANT (2026)If you are working through this problem with…
// SOLVING THIS WITH AN AI ASSISTANT (2026)If you are working through this problem with…
// SOLVING THIS WITH AN AI ASSISTANT (2026)If you are working through this problem with…
// SOLVING THIS WITH AN AI ASSISTANT (2026)If you are working through this problem with…
This website uses cookies.