Skip to content

Commit fd3fa43

Browse files
authored
Merge pull request #1332 from ImmidiSivani/main
added atleast 2 greater elements java solution
2 parents 9950a4f + ddb3cda commit fd3fa43

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

dsa-solutions/gfg-solutions/0003-at-least-two-greater-elements.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,24 @@ The problem is to find all elements in an array except the two greatest elements
8282
}
8383
};
8484
```
85-
8685
</TabItem>
86+
<TabItem value="Java" label="java">
87+
<SolutionAuthor name="@ImmidiSivani"/>
88+
```Java
89+
class Solution {
90+
public long[] findElements( long a[], long n)
91+
{
92+
// Your code goes here
93+
long[] ans=new long[a.length-2];
94+
Arrays.sort(a);
95+
for(int i=0;i<a.length-2;i++){
96+
ans[i]=a[i];
97+
}
98+
return ans;
99+
}
100+
}
101+
```
102+
</TabItem>
87103
</Tabs>
88104

89105

@@ -122,4 +138,4 @@ Auxiliary Space: The auxiliary space complexity is $O(N)$ because the sorting al
122138

123139
- **Geeks for Geeks Problem:** [Geeks for Geeks Problem](https://www.geeksforgeeks.org/problems/at-least-two-greater-elements4625/1?page=1&difficulty=School&sortBy=difficulty)
124140
- **Solution Link:** [At Least Two Greater Elements on Geeks for Geeks](https://www.geeksforgeeks.org/problems/at-least-two-greater-elements4625/1?page=1&difficulty=School&sortBy=difficulty)
125-
- **Authors LeetCode Profile:** [Anoushka](https://www.geeksforgeeks.org/user/iamanolive/)
141+
- **Authors LeetCode Profile:** [Anoushka](https://www.geeksforgeeks.org/user/iamanolive/)

0 commit comments

Comments
 (0)