Skip to content

Instantly share code, notes, and snippets.

View SuryaPratapK's full-sized avatar

Surya Pratap SuryaPratapK

  • Durgapur
View GitHub Profile
//Followup with K increasing subsequence
class Solution {
public:
bool increasingTriplet(vector<int>& nums) {
int n=nums.size();
int k=3;
vector<long long> increasing(k,LONG_MAX);
//Find an increasing subsequence of length k
for(int i=0;i<n;++i){
class Solution {
public:
vector<int> closestPrimes(int left, int right) {
//Apply sieve of eratosthenes
vector<bool> isPrime(right+1,true);
for(int i=2;i*i<=right;++i){
if(isPrime[i]==true){
for(int j=2;i*j<=right;++j)
isPrime[i*j]=false;
}
class Solution {
bool isPalindrome(int no){
string s = to_string(no);
int left=0,right=s.size()-1;
while(left<right){
if(s[left]!=s[right])
return false;
left++;
right--;
}
class Solution {
long long permutation(int count,int MOD){
long long ans = 1;
for(int i=2;i<=count;++i)
ans = (ans*i)%MOD;
return ans;
}
public:
int numPrimeArrangements(int n) {
int MOD = 1e9+7;
class Solution {
void calculate_longestPrefixSuffix(string &needle,int m,vector<int>& lps){
int l=0,r=1;
while(r<m){
//If R-th char matches with L-th char
if(needle[l]==needle[r]){
lps[r] = 1+l;
l++;
r++;
} else {
class Solution {
public:
int bagOfTokensScore(vector<int>& tokens, int power) {
int n = tokens.size();
sort(tokens.begin(),tokens.end());//sort to make choice-maing obvious
//2-pointer approach
int left=0,right=n-1;
int score = 0,ans = 0;
while(left<=right){
class Solution {
public:
vector<int> findSubstring(string s, vector<string>& words) {
unordered_map<string,int> freq,curr;
for(string& word: words)
freq[word]++;
int len = s.size();
int n = words.size();
int wordSize = words[0].size();
class Solution {
public:
string maximumOddBinaryNumber(string s) {
int count = 0;
int n = s.size();
for(int i=0;i<n;++i){
if(s[i]=='1'){
count++;
s[i]='0'; //Reset value to 0
}
class Solution {
#define ll long long
public:
long long largestSquareArea(vector<vector<int>>& bottomLeft, vector<vector<int>>& topRight) {
int n = bottomLeft.size();
vector<vector<int>> rectangles(n,vector<int>(4));
for(int i=0;i<n;i++){
rectangles[i][0] = bottomLeft[i][0];
rectangles[i][1] = bottomLeft[i][1];
rectangles[i][2] = topRight[i][0];
class Solution {
public:
int maxNumberOfFamilies(int n, vector<vector<int>>& rseats) {
rseats.push_back({0,10});
rseats.push_back({n+1,1});
sort(rseats.begin(),rseats.end());
int size = rseats.size();
int count = 0;
int skipRows,skipCols;