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 { | |
vector<vector<int>> mem; | |
bool subsetSum(vector<int>& nums,int n,int pos,int sum) | |
{ | |
if(sum==0) //Sum found | |
return true; | |
else if(pos>=n || sum<0) //Out of bounds | |
return false; | |
if(mem[pos][sum]!=-1) | |
return mem[pos][sum]; |
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
static int speedUp=[](){ | |
std::ios::sync_with_stdio(false); | |
cin.tie(nullptr); | |
cout.tie(nullptr); | |
return 0; | |
}(); | |
class Solution { | |
public: | |
int ladderLength(string beginWord, string endWord, vector<string>& wordList) { |
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 { | |
public: | |
int singleNumber(vector<int>& nums) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(NULL); | |
//Using XOR + AND combination | |
int ones = 0; | |
int twos = 0; | |
for(auto ele: nums) |
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 { | |
void dfs(vector<vector<int>>& image, int sr, int sc,int newColor,int rows,int cols,int source) | |
{ | |
if(sr<0 || sr>=rows || sc<0 || sc>=cols) | |
return; | |
else if(image[sr][sc]!=source) | |
return; | |
image[sr][sc] = newColor; | |
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 { | |
public: | |
int subarraySum(vector<int>& nums, int k) { | |
//For fast I/O in C++ | |
ios_base::sync_with_stdio(false); | |
cin.tie(NULL); | |
int n = nums.size(); | |
if(n==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
// C++ program to implement a stack that supports | |
// getMinimum() in O(1) time and O(1) extra space. | |
#include <bits/stdc++.h> | |
using namespace std; | |
// A user defined stack that supports getMin() in | |
// addition to push() and pop() | |
struct MyStack | |
{ | |
stack<int> s; |
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
// A Stack based C++ program to find next | |
// greater element for all array elements. | |
#include <bits/stdc++.h> | |
using namespace std; | |
/* prints element and NGE pair for all | |
elements of arr[] of size n */ | |
void printNGE(int arr[], int n) { | |
stack < int > s; |
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
// Program to find minimum number of platforms | |
// required on a railway station | |
#include<iostream> | |
#include<algorithm> | |
using namespace std; | |
// Returns minimum number of platforms reqquired | |
int findPlatform(int arr[], int dep[], int 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
Implementation using C++ programming | |
#include <iostream> | |
#define SIZE 5 /* Size of Circular Queue */ | |
using namespace std; | |
class Queue { | |
private: | |
int items[SIZE], front, rear; |
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<cstdlib> | |
using namespace std; | |
struct node{ | |
int data; | |
struct node *left; | |
struct node *right; | |
}; |
NewerOlder