This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
// Considering only small alphabets | |
class TrieNode { | |
public: | |
TrieNode* children[26]; | |
bool endOfWord; | |
int count; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* * * | |
Given an input string and a dictionary of words, find out if the input string can be segmented into a space-separated sequence of dictionary words. See following examples for more details. | |
* * */ | |
#include<bits/stdc++.h> | |
using namespace std; | |
class TrieNode { | |
public: | |
bool endOfWord; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int maxMeetings(int start[], int end[], int n) { | |
vector<int> order(n); | |
iota(order.begin(), order.end(), 0); | |
sort(order.begin(), order.end(), [&](int a, int b) -> bool { | |
return end[a] < end[b]; | |
}); | |
pair<int, int> last = {start[order[0]], end[order[0]]}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<int> JobScheduling(Job arr[], int n) { | |
vector<int> slots(n, -1); | |
sort(arr, arr+n, [&](const Job &a, const Job &b) -> bool { | |
return a.profit > b.profit; | |
}); | |
for(int i=0; i<n; i++) { | |
int index = min(arr[i].dead, n)-1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int findIndex(vector<int>& pre, int l, int r, int v) { | |
while (l <= r) { | |
if (pre[l] > v) return l; | |
l++; | |
} | |
return -1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Author: Saurav Kumar Gupta | |
Problem: Minimum time taken by each job to be completed given by a Directed Acyclic Graph | |
Data Structures: Queue, Array | |
*/ | |
#include "./../my_lib.h" | |
vector<int> adj[100005]; | |
void findMinTime(int V) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "./../my_lib.h" | |
vector<pair<int, int>> adj[100005]; | |
void primsBrute(int V) { | |
vector<int> key(V, INT_MAX); | |
vector<int> parent(V, -1); | |
vector<bool> MST(V, false); | |
key[0] = 0; | |
parent[0] = -1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "./../my_lib.h" | |
vector<pair<int, int>> adj[100005]; | |
void primsBrute(int V) { | |
vector<int> key(V, INT_MAX); | |
vector<int> parent(V, -1); | |
vector<bool> MST(V, false); | |
key[0] = 0; | |
parent[0] = -1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution | |
{ | |
public: | |
//Function to find sum of weights of edges of the Minimum Spanning Tree. | |
class Node { | |
public: | |
int wt, u, v; | |
Node() {} | |
Node(int wt, int u, int v) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://practice.geeksforgeeks.org/problems/flattening-a-linked-list/1# | |
struct Node{ | |
int data; | |
struct Node * next; | |
struct Node * bottom; | |
Node(int x){ | |
data = x; |
OlderNewer