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
class Solution { | |
// denotes the 8 neighbors of a grid cell | |
int row_dirs[8] = {0, 0, -1, 1, -1, -1, 1, 1}; | |
int col_dirs[8] = {-1, 1, 0, 0, -1, 1, -1, 1}; | |
int rows, cols; | |
public: | |
void dfs_helper(int r, int c, vector<vector<int>> &grid, int &cur_area) { | |
// base case: corner cases of the matrix | |
// when you encounter 0: there won't be adjacent neighbor calls | |
if(r < 0 || c < 0 || r >= rows || c >= cols || grid[r][c] == 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
//Function to find length of longest increasing subsequence. | |
// O(nlogn) solution using Binary Search + DP | |
int longestSubsequence(int n, int arr[]) { | |
// your code here | |
/* | |
Notation: | |
1) ith index means length of increasing subseq = i | |
2) ith index will contain the smallest ending element of the LIS of length i | |
*/ | |
vector<int> dp(n + 1, INT_MAX); |
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
//Function to return the maximum sum without adding adjacent elements. | |
// include/ exclude DP | |
long long maximumSum(int arr[], int sizeOfArray) { | |
//Your code here | |
// edge case: if all the elements are negative | |
bool flag = true; | |
int max_val = INT_MIN; | |
for(int i = 0; i < sizeOfArray; i++) { | |
if(arr[i] > 0) { | |
flag = false; |
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 <bits/stdc++.h> | |
using namespace std; | |
struct Node{ | |
bool isEndOfWord; | |
int count1; | |
map<char, Node *> mp; | |
}; | |
Node *newNode(){ |
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 <stdio.h> | |
int main() | |
{ | |
char info[100]; | |
char dept[ ] = "HR"; | |
int emp = 75; | |
sprintf(info, "The %s dept has %d employees.", dept, emp); | |
printf("%s\n", info); | |
return 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 <stdio.h> | |
int main() | |
{ | |
char info[ ] = "Snoqualmie WA 13190"; | |
char city[50]; | |
char state[50]; | |
int population; | |
sscanf(info, "%s %s %d", city, state, &population); | |
printf("%d people live in %s, %s.", population, city, state); |
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 <iostream> | |
using namespace std; | |
class SocialWebsite { | |
private: | |
protected: | |
public: | |
virtual void secret() = 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 <iostream> | |
#include <fstream> | |
using namespace std; | |
int main() { | |
ofstream MyFile; | |
// open the file | |
MyFile.open("test.txt"); | |
MyFile << "Some text. \n"; |
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 <iostream> | |
using namespace std; | |
int main() { | |
try { | |
double num1; | |
cout <<"Enter the first number:"; | |
cin >> num1; | |
double num2; |
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
/********************************************/ | |
/************* HOW TO USE TYPES *************/ | |
/********************************************/ | |
#include <iostream> | |
using namespace std; | |
/* This can be used indifferently for any type */ | |
template<typename T> | |
void print_data(T output){ | |
cout << output << endl; |
NewerOlder