Skip to content

Commit

Permalink
Merge pull request #472 from aman9211-max/master
Browse files Browse the repository at this point in the history
inital commit
  • Loading branch information
MukulCode authored Oct 29, 2022
2 parents d78bcc8 + 37d008c commit 1f5533c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cpp/job-scheduling-problem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Solution {
public:
int dp[305][15];
int find(vector<int> &diff, int d, int i) {
if(d == 1) {
if(i == diff.size()) {
return INT_MAX / 4;
}
int mx = -1;
for(int j = i; j < diff.size(); j++) {
mx = max(diff[j], mx);
}

return mx;
}
if(dp[i][d] != -1) {
return dp[i][d];
}
int mx = -1;
int ans = INT_MAX / 2;
for(int j = i; j < diff.size() - d + 1; j++) {
mx = max(diff[j], mx);

ans = min(ans, mx + find(diff, d - 1, j + 1));
}
return dp[i][d] = ans;
}
int minDifficulty(vector<int>& jobDifficulty, int d) {
memset(dp, -1, sizeof dp);
int ans = find(jobDifficulty, d, 0);
return (ans >= INT_MAX / 2 ? -1 : ans);
}
};
30 changes: 30 additions & 0 deletions cpp/top-k-frequent-words.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Solution {
public:

static bool comp(pair<int, string> &a, pair<int, string> &b) {
return (a.first == b.first ? a.second < b.second : a.first > b.first);
}

vector<string> topKFrequent(vector<string>& words, int k) {

map<string, int> m;
for(auto i : words) {
m[i]++;
}
vector<pair<int, string> > ans;
for(auto i : m) {
ans.push_back({i.second, i.first});

}
vector<string> res;
sort(ans.begin(), ans.end(), comp);

for(int i = 0; i < k; i++) {
res.push_back(ans[i].second);
}
return res;



}
};

0 comments on commit 1f5533c

Please sign in to comment.