Sardar Vallabhbhai National Institute of Technology 2026
C++ - Default language
My Stats
EXP gained
10087
Level
7 (Expert)
Community stats
Discussions
0
5
Know more
155
Total problems solved
128
Easy
27
Moderate
0
Hard
0
Ninja

Current streak:

0 days

Longest streak:

34 days

Less

More

Achievements
1
Ronin
Topics
Sorting
1
Samurai
Topics
Arrays

1 Time topper

Sardar Vallabhbhai National Institute of Technology

671 average partcipants
Discussions
Easiest Solution
Interview problems

vector<int> sumInRanges(vector<int> &arr, int n, vector<vector<long long>> &queries, int q) {

// Write your code here

vector<int> ans;

// if(n==0){

//     return ans;

// }

long long d,sum =0,s,s1,m;

for(int i=0;i<n;i++){

sum += arr[i];

}

for(int i=0;i<q;i++){

d=(queries[i][1]-queries[i][0] + 1)/n * sum;

// m=(queries[i][2] % n)-(queries[i][1] %n);

s=(queries[i][1]-queries[i][0] +1) % n;

s1 = queries[i][0] % n;

int d1 = 0;

for(int j=0;j<s;j++){

d1 += arr[(s1-1+j+n)%n];

}

// cout<<queries[0][0];

int as = (d+d1)% (1000000000+7);

ans.push_back(as);

}

return ans;

}

AkshayAmin
Published On 17-Oct-2023
426 views
0 replies
Easiest Solution
Interview problems

#include <map>

int subarraysWithSumK(vector < int > a, int b) {

// Write your code here

map<int,int> mp;

mp[0]=1;

int x=0,c=0;

for(int i=0;i<a.size();i++){

x=x^a[i];

int target = b^x;

c += mp[target];

mp[x]++;

}

return c;

}

AkshayAmin
Published On 15-Oct-2023
108 views
0 replies
Easiest Solution
Interview problems

#include <map>

int subarraysWithSumK(vector < int > a, int b) {

// Write your code here

map<int,int> mp;

mp[0]=1;

int x=0,c=0;

for(int i=0;i<a.size();i++){

x=x^a[i];

int target = b^x;

c += mp[target];

mp[x]++;

}

return c;

}

AkshayAmin
Published On 15-Oct-2023
108 views
0 replies
Easiest Method in C++
Interview problems

vector<int> Klargest(vector<int> &a, int k, int n) {

// Write your code here

sort(a.begin(),a.end());

vector<int> ans;

for(int i = n-k;i<=n-1;i++){

ans.push_back(a[i]);

}

return ans;

}

AkshayAmin
Published On 12-Oct-2023
153 views
1 replies