This file contains 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
#include <iostream> | |
#include <iomanip> | |
#include <string> | |
#include <vector> | |
#include <utility> | |
#include <limits> | |
#include <cstdint> | |
using Matrix = std::vector<std::vector<int>>; |
This file contains 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
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
#include <iterator> | |
#include <utility> | |
template <class ForwardIterator, class Comp = std::less<>> | |
auto maxSum(ForwardIterator begin, | |
ForwardIterator end, | |
Comp comp = Comp()) { |
This file contains 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
#include <iostream> | |
#include <string> | |
#include <algorithm> | |
#include <unordered_map> | |
#include <array> | |
int LCSNaive(std::string x, std::string y, int n, int m) | |
{ | |
if (m == 0 || n == 0) { | |
return 0; |
This file contains 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
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
#include <iterator> | |
template <class ForwardIterator, class Comp = std::less<>> | |
auto lis(ForwardIterator begin, | |
ForwardIterator end, | |
Comp comp = Comp()) { | |
This file contains 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
#include <iostream> | |
#include <unordered_map> | |
#include <vector> | |
#include <string> | |
#include <algorithm> | |
template <class T> | |
auto&& minusKFromAll(std::vector<T> v, T k) { | |
std::transform(std::begin(v), std::end(v), std::begin(v), [](T i) { return i - 1; }); |
This file contains 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
1) Find the last element of a list. | |
xs = [1, 2, 3, 4] | |
last xs | |
2) Find the last but one element of a list. | |
xs = [1, 2, 3, 4] | |
last (init xs) | |
3) Find the K'th element of a list. The first element in the list is number 1. | |
xs = [1, 2, 4, 3, 5, 6, 8, 7] |
This file contains 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
template <class T> | |
auto countingSort(const std::vector<T>& vec) | |
{ | |
if(vec.size() <= 1) std::move(vec); | |
std::vector<T> counts(vec.size(), 0); | |
const auto size = vec.size(); | |
for(size_t i = 0; i < size - 1; ++i) | |
{ |
This file contains 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
#include <iostream> | |
#include <cmath> | |
#include <vector> | |
using ull = unsigned long long; | |
bool isPrime(int n) | |
{ | |
for(int i = 2; i < n / 2; i++) | |
{ |
This file contains 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
#include <vector> | |
#include <iostream> | |
using ull = unsigned long long; | |
ull fast_power(ull num, int power) | |
{ | |
if(num < 0 || power < 0) { | |
std::cout << "invalid arguments specified\n"; | |
} |
This file contains 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
#include <iostream> | |
#include <string> | |
#include <algorithm> | |
void solution(std::string str) { | |
str += " "; | |
auto size = str.size(); | |
size_t start = 0; | |
for(size_t i = 0; i < size; i++) { | |
size_t end = str.find(' ', start); |