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
#include <cmath> | |
// Repasado 2 veces | |
using namespace std; | |
class BinaryTree { | |
public: | |
int value; | |
BinaryTree *left; | |
BinaryTree *right; |
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
using namespace std; | |
// Repasado 2 veces | |
bool isValidSubsequence(vector<int> array, vector<int> sequence) { | |
int i = 0; | |
int seqIndex = 0; | |
while (i < array.size()) { | |
cout << "top= " << array[i] << endl; | |
cout << "sequence= " << sequence[seqIndex] << 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
#include <vector> | |
#include <unordered_set> | |
using namespace std; | |
// Repasado 2 veces | |
vector<int> twoNumberSum(vector<int> array, int targetSum) { | |
unordered_set<int> targets; | |
for (int i = 0; i < array.size(); i++) { | |
int y = targetSum - array[i]; | |
if (targets.find(y) != targets.end()) { |
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 traverseLevelOrder() { | |
if (head == nullptr) return; | |
std::cout << "-- LEVEL ORDER TRAVERSE" << std::endl; | |
std::queue<BSTNode*> queue; | |
queue.push(head); | |
while (!queue.empty()) { | |
BSTNode* current = queue.front(); | |
std::cout << queue.front()->value << std::endl; | |
if (current->left != nullptr) queue.push(current->left); | |
if (current->right != nullptr) queue.push(current->right); |
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
// sum(1)(2)(3)(4)..( n)() | |
const sum = (a) => { | |
return (b) => b ? sum(a + b) : a; | |
} | |
console.log(sum(1)(2)(3)(4)()); |
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
#include <vector> | |
#include <climits> | |
using namespace std; | |
// O(dn) time | O(n) space | |
int minNumberOfCoinsForChange(int n, vector<int> denoms) { | |
// Create a matrix, to store the best possiblitites until target. | |
vector<int> numOfCoins(n + 1, INT_MAX); // +1, to include zero. | |
numOfCoins[0] = 0; // Starts at zero because, how many 0 coins do I need to make 0 in value. | |
for (int denomination : denoms) { |
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
#include <vector> | |
using namespace std; | |
class AncestralTree { | |
public: | |
char name; | |
AncestralTree *ancestor; | |
AncestralTree(char name) { | |
this->name = name; |
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
#include <vector> | |
using namespace std; | |
vector<vector<int>> getUnvisitedNeighbors(int i, int j, vector<vector<int>> matrix, vector<vector<int>>& visited) { | |
vector<vector<int>> unvisitedNeighbors{}; | |
// Top | |
if (i > 0 && !visited[i - 1][j]) { | |
unvisitedNeighbors.push_back({ i - 1, j}); | |
} | |
// Bottom |
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
using namespace std; | |
int getNextIdx(int currentIdx, vector<int>& array) { | |
int nextIdx = (currentIdx + array[currentIdx]) % (int)array.size(); | |
return nextIdx >= 0 ? nextIdx : nextIdx + array.size(); | |
} | |
bool hasSingleCycle(vector<int> array) { | |
int currentIdx = 0; | |
int numberJumps = 0; |
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
#include <vector> | |
using namespace std; | |
vector<int> searchInSortedMatrix(vector<vector<int>> matrix, int target) { | |
int col = matrix[0].size() - 1; | |
int row = 0; | |
while (row < matrix.size() && col >= 0) { | |
if (target < matrix[row][col]) { | |
col--; |