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 maximumTripletValue(vector<int>& nums) {
int n = nums.size();
//Step-1: Find right_max for all indices
vector<int> right_max(n);
int max_val = nums[n-1];//last element
for(int i=n-2;i>0;--i){
right_max[i] = max_val;
class Solution {
#define ll long long
ll findMaxPoints(vector<vector<int>>& questions,int pos,vector<ll>& mem){
if(pos >= questions.size())
return 0;
if(mem[pos]!=-1)
return mem[pos];
ll exclude = findMaxPoints(questions,pos+1,mem);
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
class Solution {
#define ll long long
int MOD = 1000000007;
ll binaryExponentiation(ll a,ll b){
ll res = 1;
while(b){
if(b&1)
res = (res * a) % MOD;
a = (a * a) % MOD;
class Solution {
int mooresVotingAlgo(vector<int>& nums){
int majority_element = nums[0];
int freq = 1;
for(int i=1;i<nums.size();++i){
if(nums[i]!=majority_element) freq--;
else freq++;
if(freq==0){
majority_element = nums[i];
class Solution {
#define ll long long
#define pii pair<ll,ll>
ll MOD = 1e9+7;
void calculateScore(vector<int>& nums,vector<ll>& score){
for(ll ele: nums){
ll count=0;
for(ll i=2;i*i<ele;++i){
if(ele%i==0)
class Solution {
#define pii pair<int,int>
#define pip pair<int,pii>
bool isValid(int& x,int& y,int& m,int& n){
return (x>=0 and x<m and y>=0 and y<n);
}
public:
vector<int> maxPoints(vector<vector<int>>& grid, vector<int>& queries) {
set<int> sorted_queries(queries.begin(),queries.end());//We need to only solve for unique query
class Solution {
public:
int minOperations(vector<vector<int>>& grid, int x) {
vector<int> array;
int remainder = grid[0][0]%x;
//Step-1: Insert array elements
for(int i=0;i<grid.size();++i){
for(int j=0;j<grid[0].size();++j){
if(grid[i][j]%x != remainder)
class Solution {
#define pii pair<int,int>
bool countLineIntersections(vector<pii>& coordinates){
int lines = 0;
int overlap = 0;
for(int i=0;i<coordinates.size();++i){
if(coordinates[i].second==0) overlap--;
else overlap++;
if(overlap==0)
class Solution {
#define pii pair<int,int>
public:
int countDays(int days, vector<vector<int>>& meetings) {
vector<pii> time;
for(auto& meeting: meetings){
time.push_back(make_pair(meeting[0],1));
time.push_back(make_pair(meeting[1]+1,0));
}
sort(time.begin(),time.end());