Skip to content

Instantly share code, notes, and snippets.

View SuryaPratapK's full-sized avatar

Surya Pratap SuryaPratapK

  • Durgapur
View GitHub Profile
class Solution {
#define ll long long
public:
long long maximumSubarraySum(vector<int>& nums, int k) {
int n=nums.size();
ll max_sum=0;
unordered_map<int,int> freq;
ll win_sum=0;
for(int i=0;i<n;++i){
class Solution {
public:
vector<int> resultsArray(vector<int>& nums, int k) {
int n=nums.size();
vector<int> res;
deque<int> dq;
for(int i=0;i<n;++i){
if(!dq.empty() and dq.front()<=i-k) //Remove elements outside of current window
dq.pop_front();
class Solution {
void fill(vector<vector<char>>& res,int count,int x,int y){
while(count){
res[x][y]='#';
x--;
count--;
}
}
public:
vector<vector<char>> rotateTheBox(vector<vector<char>>& box) {
class Solution {
public:
int findLengthOfShortestSubarray(vector<int>& arr) {
int n=arr.size();
int l=0;
int r=n-1;
//Skip from right
while(r>0 and arr[r]>=arr[r-1])
r--;
class Solution {
int binarySearch(vector<vector<int>>& items,int price){
int max_beauty=0;
int l=0,h=items.size()-1;
int mid;
while(l<=h){
mid = l+(h-l)/2;
if(items[mid][0]<=price){
max_beauty = max(max_beauty,items[mid][1]);
class Solution {
#define ll long long
public:
long long countFairPairs(vector<int>& nums, int lower, int upper) {
int n=nums.size();
sort(nums.begin(),nums.end());
ll ans=0;
for(int i=0;i<n-1;++i){
int lb = lower_bound(nums.begin()+i+1,nums.end(),lower-nums[i])-nums.begin();
class Solution {
void updateFreq(vector<int>& bitFreq,int number,int val){
for(int i=0;i<32;++i)
if(number&(1<<i))
bitFreq[i]+=val;
}
int getNumber(vector<int>& bitFreq){
int number=0;
long long pow = 1;
for(int i=0;i<32;++i){
class Solution {
#define ll long long
vector<int> getBin(int n){
vector<int> res;
while(n){
if(n&1) res.push_back(1);
else res.push_back(0);
n>>=1;
}
return res;
class Solution {
void sieveOfEratosthenes(vector<int>& primes,int maxVal){
bool sieve[maxVal+1];
memset(sieve,false,sizeof(sieve));
for(int i=2;i*i<maxVal;++i){
if(sieve[i]==false){
for(int j=2;i*j<maxVal;++j)
sieve[i*j]=true;
}
}
class Solution {
public:
vector<int> getMaximumXor(vector<int>& nums, int maximumBit) {
int n=nums.size();
vector<int> prefix_xor(n);
prefix_xor[0]=nums[0];
for(int i=1;i<n;++i)
prefix_xor[i] = prefix_xor[i-1] ^ nums[i];