Skip to content

Instantly share code, notes, and snippets.

View SuryaPratapK's full-sized avatar

Surya Pratap SuryaPratapK

  • Durgapur
View GitHub Profile
class FindSumPairs {
vector<int> arr1,arr2;
unordered_map<int,int> ele_freq;
public:
FindSumPairs(vector<int>& nums1, vector<int>& nums2) {
arr1 = nums1;
arr2 = nums2;
for(int ele: nums2)
ele_freq[ele]++;
}
class Solution {
int MOD = 1e9+7;
public:
int possibleStringCount(string word, int k) {
//STEP-1: Make runs array
int n = word.size();
vector<int> runs(1,1);
for(int i=1;i<n;++i){
if(word[i]==word[i-1]) runs.back()++;
else runs.push_back(1);
class Solution {
int MOD = 1e9+7;
void precomputePowerOfTwo(vector<int>& power_of_two,int& n){
power_of_two[0]=1;
for(int i=1;i<n;++i)
power_of_two[i] = (power_of_two[i-1]*2LL)%MOD;
}
public:
int numSubseq(vector<int>& nums, int target) {
int n = nums.size();
class Solution {
#define ll long long
public:
char kthCharacter(long long k, vector<int>& operations) {
int count_ops=0;
ll val = k;
while(val>1){
int jumps = ceil(log2(val));
val -= pow(2,jumps-1);
count_ops += operations[jumps-1];
class Solution {
int countSubsequences(const string& s,const string& next){
int i=0;//Index in s
int j=0;//Index in next
int m = next.size();
int subsequence_count = 0;
while(i<s.size()){
if(s[i]==next[j]){
j++;
class Solution {
public:
int longestSubsequence(string s, int k) {
int n = s.size();
//Step-1: Keep all set bits until value exceeds k
long long val = 0;
int i=0;
while(i<min(n,32)){
if(s[n-i-1]=='1'){
long long power = pow(2,i);
class Solution {
public:
vector<vector<int>> divideArray(vector<int>& nums, int k) {
sort(nums.begin(),nums.end());
int n=nums.size();
vector<vector<int>> res;
for(int i=2;i<n;i+=3){
if(nums[i]-nums[i-2]>k)
return {};
class Solution {
using ll = long long;
int MOD = 1e9+7;
vector<int> fact,inv_fact;
int binaryExp(ll a,ll b){
ll res = 1;
while(b){
if(b&1)
res = (res*a)%MOD;
class Solution {
public:
int maxDiff(int num) {
string s = to_string(num);
string max_s = s;
string min_s = s;
int n = s.size();
//Maximize number: The first digit<9 should be made 9
for(int i=0;i<n;++i){
class Solution {
bool isPossible(vector<int>& nums,const int& val,const int& p){
int count = 0;
int i=1;
while(i<nums.size()){
if(nums[i]-nums[i-1] <= val){
count++;
i+=2;
}else{
i++;