Skip to content

Instantly share code, notes, and snippets.

View piusayowale's full-sized avatar

OGUNLEYE AYOWALE piusayowale

  • Lagos, Nigeria
View GitHub Profile
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++;
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;
@piusayowale
piusayowale / bracketMatch.cpp
Created August 28, 2022 16:47
Stack and queue problem (bracket match)
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;
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++){
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;
}
@piusayowale
piusayowale / decentNumber.cpp
Created August 19, 2022 11:58
form decent number hackerranck
void decentNumber(int n) {
int res = -1;
for (int i = 0; i <= n; ++i)
{
if (i % 5 == 0)
{
int j = n - i;
@piusayowale
piusayowale / recursive_digit_sum.cpp
Created August 17, 2022 21:11
get the recursive digit sum, still in review
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);
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];
}
@piusayowale
piusayowale / climbingleaderboard.cpp
Created August 17, 2022 16:29
this solution is still failing for 2 cases
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";
@piusayowale
piusayowale / grid_sorting.cpp
Created August 16, 2022 18:04
grid sorting greedy approach
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];