Skip to content

added atleast 2 greater elements java solution #1332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,24 @@ The problem is to find all elements in an array except the two greatest elements
}
};
```

</TabItem>
<TabItem value="Java" label="java">
<SolutionAuthor name="@ImmidiSivani"/>
```Java
class Solution {
public long[] findElements( long a[], long n)
{
// Your code goes here
long[] ans=new long[a.length-2];
Arrays.sort(a);
for(int i=0;i<a.length-2;i++){
ans[i]=a[i];
}
return ans;
}
}
```
</TabItem>
</Tabs>


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

- **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)
- **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)
- **Authors LeetCode Profile:** [Anoushka](https://www.geeksforgeeks.org/user/iamanolive/)
- **Authors LeetCode Profile:** [Anoushka](https://www.geeksforgeeks.org/user/iamanolive/)
Loading