Skip to content

Instantly share code, notes, and snippets.

View piusayowale's full-sized avatar

OGUNLEYE AYOWALE piusayowale

  • Lagos, Nigeria
View GitHub Profile
long arrayManipulation(int n, vector<vector<int>> queries) {
vector<int> arr(n / 2, 0);
for (auto i: queries) {
arr[i[0] - 1] += i[2];
if (i[1] != arr.size()) {
continue;
}
}
@piusayowale
piusayowale / Haroldisakidnapper.cpp
Created June 22, 2022 16:41
Harold is a kidnapper who wrote a ransom note, but now he is worried it will be traced back to him through his handwriting. He found a magazine and wants to know if he can cut out whole words from it and use them to create an untraceable replica of his ransom note. The words in his note are case-sensitive and he must use only whole words availab…
void checkMagazine(vector<string> magazine, vector<string> note) {
if(magazine.size() < 1 || magazine.size() > 30000){
std::cout << "No\n";
return;
}
if(note.size() < 1 || note.size() > 30000){
std::cout << "No\n";
return;
}
map<string, int> words;
@piusayowale
piusayowale / issubstring.cpp
Created June 23, 2022 12:33
Given two strings, determine if they share a common substring. A substring may be as small as one character.
string twoStrings(string s1, string s2) {
set<char> f(s1.begin(), s1.end());
std::cout << s1 << "\n" << s2 << "\n\n";
for(auto i : s2){
std::cout << i << "\n";
auto ret = f.insert(i);
if(ret.second == false){
@piusayowale
piusayowale / queryForFrequency.cpp
Created July 8, 2022 11:40
You are given q queries. Each query is of the form two integers described below:
vector<int> freqQuery(vector<vector<int>> queries) {
map<int, int> freqStore, freqKey;
vector<int> output;
int counter = 0;
for(size_t n = 0; n < queries.size(); n++){
counter = queries[n][0] % 3;
if(counter == 1){
freqKey[freqStore[queries[n][1]]]--;
void countSwaps(vector<int> a) {
int n = a.size();
int swapCounter = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - 1; j++) {
if (a[j] > a[j + 1]) {
swap(a[j], a[j + 1]);
swapCounter++;
int maximumToys(vector<int> prices, int k) {
sort(prices.begin(), prices.end());
int count = 0;
int totalSum = 0;
while (totalSum < k) {
totalSum = totalSum + prices[count];
count++;
}
return count - 1;
class Checker{
public:
// complete this method
static int comparator(Player a, Player b) {
if (a.score < b.score) {
return -1;
} else if (a.score > b.score) {
return 1;
} else if(a.name > b.name){
return -1;
@piusayowale
piusayowale / sdl_with_boost_geometry.cpp
Last active July 10, 2022 11:02
checking button click with SDL and boost geometry
// sdl_opengl.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_surface.h>
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_opengl.h>
#include <boost/geometry.hpp>
@piusayowale
piusayowale / sdl_draganddrop.cpp
Last active July 10, 2022 16:39
SDL DRAG AND DROP WITH BOOST.GEOMETRY
// sdl_opengl.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_surface.h>
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_opengl.h>
#include <boost/geometry.hpp>
@piusayowale
piusayowale / sdl_draganddrop2.cpp
Created July 10, 2022 16:43
DRAG AND DROP WITH BOOST.GEOMETRY
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_surface.h>
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_opengl.h>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/geometries/register/box.hpp>