Skip to content

Commit

Permalink
problem solution with .gitignore file added
Browse files Browse the repository at this point in the history
  • Loading branch information
Faruk Hossain Milon committed Oct 8, 2020
1 parent 43ae386 commit 0475969
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .gitignore

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.o
.exe
32 changes: 32 additions & 0 deletions 975_Odd_Even_Jump.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Solution {
public:
int oddEvenJumps(vector<int>& A) {
int n = A.size();
vector<vector<int>> dp(n, vector<int>(2, 0));
dp[n-1][0] = dp[n-1][1] = 1;
map<int, int> container;
int ans = 1;
container[A[n-1]] = n-1;
for(int i = n-2; i >= 0; i--) {
auto it = container.lower_bound(A[i]+1);
// cout << "For: " << i << endl;
if (it == container.begin()) {
dp[i][1] = 0;
} else {
it--;
// cout << it->second << endl;
dp[i][1] = dp[it->second][0];
}
it = container.upper_bound(A[i] - 1);
if (it == container.end()) {
dp[i][0] = 0;
} else {
// cout << "U " <<it->second << endl;
dp[i][0] = dp[it->second][1];
}
container[A[i]] = i;
ans += dp[i][0];
}
return ans;
}
};
45 changes: 45 additions & 0 deletions min_number_of_chairs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>


using namespace std;

int minNumberOfCharis(const vector<int> &arrival, const vector<int> &leave) {

map<int, int> numOfPeoples;
int n = arrival.size();
for(int i = 0; i < n; i++) {
numOfPeoples[ arrival[i] ]++;
numOfPeoples[ leave[i] ]--;
}
int counter = 0;
int mx = 0;
for(auto it : numOfPeoples) {
counter += it.second;
mx = max(mx, counter);
}
return mx;
}

int main()
{
vector<int> arr({1, 2, 6, 5, 3});
vector<int> leave({5, 5, 7, 6, 8});

cout << minNumberOfCharis(arr, leave) << endl;
return 0;
}

/*
Time complexity:
O(nlog(n))
Space complexity:
O(n)
*/
40 changes: 40 additions & 0 deletions time_to_type_a_string.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>


using namespace std;

int timeToType(string keyboard, string text) {

unordered_map<char, int> pos;
for(int i = 0; i < keyboard.size(); i++) {
pos[keyboard[i]] = i;
}
int pre = 0;
int ans = 0;
for(auto ch : text) {
ans += abs(pre - pos[ch]);
pre = pos[ch];
}
return ans;
}

int main()
{
cout << timeToType("abcdefghijklmnopqrstuvwxy", "cba") << endl;
return 0;
}

/*
Time complexity:
O(n)
Space complexity:
O(1)
*/

0 comments on commit 0475969

Please sign in to comment.