Skip to content

Instantly share code, notes, and snippets.

View SuryaPratapK's full-sized avatar

Surya Pratap SuryaPratapK

  • Durgapur
View GitHub Profile
class Solution {
int tryRotationMatching(int number,vector<int>& first,vector<int>& second){
int count = 0;
for(int i=0;i<first.size();++i){
if(first[i]==number) continue;
else if(second[i]==number) count++;
else return INT_MAX;
}
return count;
}
class Domino {
public:
void doubleDominoPush(int last_R, int pos, string& dominoes) {
while (last_R < pos) {
dominoes[last_R++] = 'R';
dominoes[pos--] = 'L';
}
}
void leftDominoPush(int start, int end, string& dominoes) {
class Solution {
bool canAssign(int mid,vector<int>& workers,vector<int>& tasks,int pills,int strength){
multiset<int> usable_workers(workers.end()-mid,workers.end());
for(int i=mid-1;i>=0;--i){
auto curr_worker = --usable_workers.end();
if(*curr_worker < tasks[i]){
if(pills<=0) return false;
//Optimal Strategy: Assign weakest worker to get the current task done
class Solution {
#define ll long long
public:
long long countSubarrays(vector<int>& nums, int minK, int maxK) {
ll valid_subarrays = 0;
int invalid_idx = -1;
int minK_idx = -1;
int maxK_idx = -1;
for(int i=0;i<nums.size();++i){
class Solution {
using ll = long long;
public:
long long countSubarrays(const vector<int>& nums, long long k) {
ll n = nums.size();
ll left = 0, right = 0; // window is [left, right)
ll sum = 0; // sum of nums[left..right-1]
ll count = 0;
while (left < n) {
class Solution {
#define ll long long
public:
long long countInterestingSubarrays(vector<int>& nums, int modulo, int k) {
ll n = nums.size();
ll pos=0;
ll interesting_subarrays = 0;
ll prefix_count = 0;
unordered_map<ll,ll> mod_freq;
class Solution {
public:
int countCompleteSubarrays(vector<int>& nums) {
unordered_set<int> unique_elements(nums.begin(),nums.end());
int unique_count = unique_elements.size();
int left = 0;
int right = 0;
int n = nums.size();
unordered_map<int,int> freq;
class Solution {
vector<int> findLPS(string& patt){
int n=patt.size();
vector<int> lps(n);
int i=1;
int j=0;
while(i<n){
if(patt[i]==patt[j]){
lps[i]=j+1;
class Solution {
#define ll long long
ll count[15][10005];
ll prefix_sum[15][10005];
ll options[15];
int MOD = 1e9+7;
void countUniqueSequences(int curr,int idx,int& maxValue){
options[idx]+=1;
class Solution {
#define ll long long
public:
int numberOfArrays(vector<int>& differences, int lower, int upper) {
ll gap = 0;
ll min_val = 0;
ll max_val = 0;
ll curr_val = 0;
for(int& ele: differences){
curr_val += ele;