Skip to content
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

H-Index #491

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
37 changes: 37 additions & 0 deletions C++/H-Index.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* medium difficulty */

class Solution{
public:
int hIndex(vector<int> &citations)
{
int n = citations.size();
int mpp[1001] = {0};

for (int i = 0; i < n; i++)
{
if (citations[i] > 1000)
{
mpp[1000]++;
}
else
{
mpp[citations[i]]++;
}
}

for (int i = 999; i >= 0; i--)
{
mpp[i] += mpp[i + 1];
}

for (int i = 1000; i >= 0; i--)
{
if (mpp[i] >= i)
{
return i;
}
}

return 0;
}
};
37 changes: 37 additions & 0 deletions C++/trapping-rain-water.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
int trap(vector<int> &height)
{
int heightSize = height.size();

int res = 0;

int lmax[heightSize], rmax[heightSize];

lmax[0] = height[0];
for (int i = 1; i < heightSize; i++)
{
lmax[i] = max(height[i], lmax[i - 1]);
}

rmax[heightSize - 1] = height[heightSize - 1];
for (int i = heightSize - 2; i >= 0; i--)
{
rmax[i] = max(height[i], rmax[i + 1]);
}

for (int i = 1; i < heightSize - 1; i++)
{
res = res + (min(lmax[i], rmax[i]) - height[i]);
}

return res;
}

// test case 1
// height = [0,1,0,2,1,0,1,3,2,1,2,1]
// output = 6

// test case 2
// height = [4,2,0,3,2,5]
// output = 9

// time complexity --> O(n)
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
| 1512 | [Number of Good Pairs](https://leetcode.com/problems/number-of-good-pairs/) | [Java](./Java/Number-of-Good-Pairs.java) | O(N^2) | O(1) | Easy | Array |
| 162 | [Find Peak element](https://leetcode.com/problems/find-peak-element/) | [javascript](https://github.com/codedecks-in/LeetCode-Solutions/blob/master/JavaScript/findPeakElement.js) | o(Logn) | O(1) | Medium | Array |
| 54 | [Spiral Matrix](https://leetcode.com/problems/spiral-matrix/) | [C++](./C++/Spiral-matrix.cpp) | O(M\*N) | O(M\*N) | Medium | Array |
| 238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/) | [C++](./C++/238.Product_of_array_except_self) | O(N) | O(N) | Medium | Array |
| 238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/) | [C++](./C++/238.Product_of_array_except_self) | O(N) | O(N) | Medium | Array ||
274 | [H-Index](https://leetcode.com/problems/h-index) | [C++](./C++/H-Index.cpp) | O(n) | O(1) | Medium | Array | |


<br/>
Expand Down Expand Up @@ -515,6 +516,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if
| [Shrimadh V Rao](https://github.com/Shrimadh) <br> <img src="https://avatars.githubusercontent.com/u/64469917?v=4" width="100" height="100"> | India | C++ | [GitHub](https://github.com/Shrimadh)
| [Shreyas Shrawage](https://github.com/shreyventure) <br> <img src = "https://avatars.githubusercontent.com/u/55741087?v=4" width="100" height="100"> | India | Python | [CodeChef](https://www.codechef.com/users/shreyventure)<br/>[LeetCode](https://leetcode.com/shreyventure/)<br/>[HackerRank](https://www.hackerrank.com/shreyas_shrawage)
| [Surbhi Mayank](https://github.com/surbhi2408) <br> <img src="https://avatars.githubusercontent.com/u/58289829?s=400&u=68fd396819b927ec4d8820d87d6d1e311c3abd01&v=4" width="100" height="100"> | India | C++ | [GitHub](https://github.com/surbhi2408)
| [Purval Bhude](https://github.com/PurvalBhude) <br> <img src="https://avatars.githubusercontent.com/u/143245454?s=96&v=4" width="100" height="100"> | India | C++ | [Linkedin](https://www.linkedin.com/in/purvalbhude)<br/>[LeetCode](https://leetcode.com/Purval_Bhude/)<br/>[Github](https://github.com/PurvalBhude)
<div align="right">
<b><a href="#algorithms">⬆️ Back to Top</a></b>
</div>
Expand Down