This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<int> jimOrders(vector<vector<int>> orders) { | |
map<int, int> num; | |
vector<int> ret; | |
int index = 0; | |
for(auto d : orders){ | |
int c = d[0] + d[1]; | |
bool ch = true; | |
while (ch) { | |
if(num[c] != 0){ | |
c++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int findMinArrowShots(vector<vector<int>>& points) { | |
sort(begin(points), end(points)); | |
int ans = 1, e = INT_MAX; | |
for (auto& p: points) { | |
if (p[0] <= e) e = min(e, p[1]); | |
else e = p[1], ans++; | |
} | |
return ans; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool isMatch(char x, char y){ | |
bool cond1 = x == '(' && y == ')'; | |
bool cond2 = x == '{' && y == '}'; | |
bool cond3 = x == '[' && y == ']'; | |
if(cond1 || cond2 || cond3){ | |
return true; | |
} | |
return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int lengthOfLongestSubstring(string s) { | |
set<char> cache; | |
int m = 0; | |
int count = 0; | |
for(int i = 0; i < s.size(); i++){ | |
cache.clear(); | |
cache.insert(s[i]); | |
count = 1; | |
for(int j = i + 1; j < s.size(); j++){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void insertionSort2(int n, vector<int> arr) { | |
int t, j; | |
for(int i = 1; i < n; i++){ | |
t = arr[i]; | |
for(j = i - 1; (j >= 0 && arr[j] > t); j--) | |
arr[j + 1] = arr[j]; | |
arr[j + 1] = t; | |
for(auto ele: arr) cout<<ele<<" "; | |
cout<<endl; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void decentNumber(int n) { | |
int res = -1; | |
for (int i = 0; i <= n; ++i) | |
{ | |
if (i % 5 == 0) | |
{ | |
int j = n - i; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
long long getsuperDigit(string num, int n){ | |
long long sum = 0; | |
string temp; | |
temp.push_back(num[n]); | |
sum = stoll(temp); | |
if(n == 0){ | |
return sum; | |
} | |
return sum + getsuperDigit(num, n - 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int diagonalDifference(vector<vector<int>> arr) { | |
int suma = 0; | |
int sumb = 0; | |
int n = arr.size(); | |
for(int i = 0; i < n; i++){ | |
cout << arr[i][i] << "\n"; | |
sumb = sumb + arr[i][i]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<int> climbingLeaderboard(vector<int> ranked, vector<int> player) { | |
vector<int> player_ranks; | |
set<int> score_cache{ranked.begin(), ranked.end()}; | |
unordered_map<int, int> dp; | |
//int dp[INT16_MAX] = {0}; segmentation fault for some cases | |
for(auto d : player){ | |
score_cache.insert(d); | |
cout << d << "\n"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string gridChallenge(vector<string> grid) { | |
size_t jj, n = grid.size(); | |
bool is_not = false; | |
for (int i = n-1; i >= 0; i--) { | |
string& r = grid[i]; | |
sort(begin(r),end(r)); | |
if (i == n-1) continue; | |
string& p = grid[i+1]; |