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
/* | |
Paste the methods below in Chrome Console (Ctrl + Shift + I), and then convert the data into JSON string using: | |
JSON.stringify(data); | |
Paste that string as a parameter to `prefillSubjectsAndGrades` method. | |
Example is given at the end of this file. | |
NOTE: If the fields change (their `id` values in particular), then the algorithm will break, and is rendered useless. | |
*/ |
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 <stdio.h> | |
#include <stdlib.h> | |
static int front = 0; | |
static int rear = 0; | |
static int capacity = 2; | |
static int* q; | |
void enq(int element) { |
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
// Problem Link: https://i.ibb.co/hVT71cp/Container-with-most-water.png | |
// Test Link: https://ide.geeksforgeeks.org/OBtxHYttjP | |
// Solution Status: Could not find this particular problem anywhere on any online judge | |
#include <stack> | |
#include <vector> | |
#include <climits> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; |
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
// Problem Link: https://leetcode.com/problems/3sum-closest/ | |
// Test Link: https://ide.geeksforgeeks.org/EBNEOuStvx | |
// Solution Status: Accepted in Leetcode Online Judge | |
class Solution { | |
public: | |
// Approach: Two-Pointer Technique. Time Complexity: Quadratic O(N^2) -- because we fix one element, and for | |
// the remaining elements, we apply two-ptr technique. | |
int threeSumClosest(vector<int>& nums, int target) { | |
sort(nums.begin(), nums.end()); // sort the array to apply two-ptr technique |
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
// Problem Link: https://practice.geeksforgeeks.org/problems/detect-cycle-in-an-undirected-graph/1/ | |
// Solution Status: Accepted by GFG Judge | |
/** | |
* GYTWrkz Solutions Interview Question | |
* ------------------------------------ | |
* Question 1: Given an Undirected Graph, find whether the Graph has a Cycle or Not (Discussed the approach with the interviewer). | |
*/ | |
#include <iostream> |
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
// Forest Definition: Disjoint Union of Acyclic Graphs (or Trees) | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
bool DFSRec(vector<int> *G, vector<bool> &visited, int curr, int parent) { | |
visited[curr] = true; | |
for(int adj: G[curr]) { | |
if(!visited[adj]) { |
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
// Check if there exists a Path from given vertices: (u, v) | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
bool DFSRec(vector<int> *G, int src, int dest, vector<bool> &visited) { | |
if(src == dest) return true; | |
visited[src] = true; | |
for(int u: G[src]) |
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
// Problem Link: https://practice.geeksforgeeks.org/problems/depth-first-traversal-for-a-graph/1/ | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
void DFSRec(vector<int> *G, int s, vector<bool> &visited, vector<int> &vertices) { | |
visited[s] = true; | |
vertices.push_back(s); | |
for(int v: G[s]) |
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 <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
void DFSRec(vector<int> *G, int src, vector<bool> &visited) { | |
visited[src] = true; | |
for(int u: G[src]) | |
if(!visited[u]) | |
DFSRec(G, u, visited); |
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
// Problem Link: https://practice.geeksforgeeks.org/problems/bfs-traversal-of-graph/1/ | |
/* Function to do BFS of graph | |
* g[]: adj list of the graph | |
* N : number of vertices | |
*/ | |
vector<int> bfs(vector<int> g[], int N) { | |
vector<int> vertices; | |
vector<bool> visited(N+1, false); | |
queue<int> Q; |
NewerOlder