Skip to content

Instantly share code, notes, and snippets.

View EduardoSaverin's full-sized avatar
:octocat:
Happy Code

Sumit Chaudhary EduardoSaverin

:octocat:
Happy Code
View GitHub Profile
// Complexity - O(n^2), Space Complexity - O(n^2)
private int[] findTriple_3(int[] A) {
Map<Integer, int[]> map = new HashMap<Integer, int[]>();
for (int i = 0, l = A.length; i < l; i++) {
map.clear();
for (int j = i + 1; j < l; j++) {
if (map.containsKey(A[j])) {
int[] pair = map.get(A[j]);
return new int[]{pair[0], pair[1], A[j]};
// Complexity - O(n^2), Space Complexity - O(n^2)
private int[] findTriple_3(int[] A) {
Map<Integer, int[]> map = new HashMap<Integer, int[]>();
for (int i = 0, l = A.length; i < l; i++) {
map.clear();
for (int j = i + 1; j < l; j++) {
if (map.containsKey(A[j])) {
int[] pair = map.get(A[j]);
return new int[]{pair[0], pair[1], A[j]};