Skip to content

Commit

Permalink
docs: adding more details in the description and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
amin authored and zanninso committed Jul 4, 2024
1 parent b270b97 commit 50f72c6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion subjects/java/checkpoints/top-frequents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Instructions

Given a non-empty array of integers, return the k most frequent elements. Use a hash map and a heap for efficient lookup and retrieval.
Given a non-empty array of integers, return the k most frequent elements. Use a hash map and a heap for efficient lookup and retrieval. The returned array should be ordered by appearance frequency first, and if there is a tie in frequency, the element with the smallest index in the original array will appear first.

### Expected Class

Expand Down Expand Up @@ -39,6 +39,11 @@ public class ExerciseRunner {
int[] nums3 = {4, 1, -1, 2, -1, 2, 3};
int k3 = 2;
System.out.println("Top " + k3 + " frequent elements: " + topFrequents.findTopKFrequent(nums3, k3));

// Test case 4
int[] nums4 = {4, 1, -1, 2, -1, 2, 3};
int k4 = 10;
System.out.println("Top " + k4 + " frequent elements: " + topFrequents.findTopKFrequent(nums4, k4));
}
}
```
Expand All @@ -51,5 +56,6 @@ $ java -cp build ExerciseRunner
Top 2 frequent elements: [1, 2]
Top 1 frequent elements: [1]
Top 2 frequent elements: [-1, 2]
Top 10 frequent elements: [-1, 2, 4, 1, 3]
$
```

0 comments on commit 50f72c6

Please sign in to comment.