Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
#include <initializer_list>
#include<bits/stdc++.h>
using namespace std;
vector<int> longestDistinctKSubarray(vector<int> nums, int k) {
vector<int> ret;
if (k == 0)
return ret;
#include <iostream>
#include <string>
#include <map>
#include<bits/stdc++.h>
using namespace std;
struct Node {
int val;
Node*next=0;
};
@dgodfrey206
dgodfrey206 / consecutive_find.cpp
Created June 21, 2019 04:09
New consecutive_find. More efficient
int consecutive_find(vector<int> arr, int n) {
for (size_t s = 0, e = 0; e < arr.size(); s = e) {
while (e < arr.size() && arr[s] == arr[e]) {
e++;
}
if (e - s == (size_t)n) {
return s;
}
}
return -1;
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
template<class T>
struct sticky_streamer_t {
std::ostream* os = nullptr;
T x;
int order;
sticky_streamer_t()=default;
xinput --set-prop "ETPS/2 Elantech Touchpad" "Device Accel Constant Deceleration" 1
@dgodfrey206
dgodfrey206 / display.cpp
Last active May 22, 2019 02:06
Self explanatory
#include <string>
#include <fstream>
#include <streambuf>
#include <ctime>
#include <iomanip>
#include <cmath>
#include <iostream>
int displayA(int n, int w) {
if (n == 0) return 0;
@dgodfrey206
dgodfrey206 / countcirclinkedlist.cpp
Last active May 19, 2019 18:35
Counts the number of nodes in a circular linked list
#include<iostream>
#include<string>
#include<map>
#include<vector>
using namespace std;
struct Node{
int data;
Node*next=nullptr;
};
@dgodfrey206
dgodfrey206 / friday.cpp
Created March 22, 2018 01:54
USACO problem
#include<bits/stdc++.h>
using namespace std;
string convert(int n) {
string arr[]={"mon","tue","wed","thur","fri","sat","sun"};
return arr[n%7];
}
string mon_convert(int n){
string arr[]={"jan","feb","mar","april","may","june","july","aug","sep","oct","nov","dec"};
@dgodfrey206
dgodfrey206 / mop.txt
Created January 3, 2018 03:11
Math Olympiad Problem
July 14
July 16
August 14
////August 15////
////August 17////
////May 15////
////May 16////
////June 17////
@dgodfrey206
dgodfrey206 / zeroOutMatrix.cpp
Last active November 18, 2017 01:56
Write an algorithm such that if an element in an MxN matrix is 0, its entire row and columns are set to 0
#include<vector>
#include<iostream>
using namespace std;
#define N 5
#define M 5
void zeroOutMatrix(int mat[N][M]) {
bool rowVisited[N] = {};
bool columnVisited[M] = {};