Skip to content

Instantly share code, notes, and snippets.

View Ch-sriram's full-sized avatar
🎯
Solving problems, one step at a time

Chandrabhatta Sriram Ch-sriram

🎯
Solving problems, one step at a time
View GitHub Profile
@Ch-sriram
Ch-sriram / wesGpaAutomate.js
Last active July 26, 2023 00:43
WES iGPA Automated Score Filler And Calculator
/*
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.
*/
@Ch-sriram
Ch-sriram / circular_q_global.c
Last active February 26, 2022 07:44
Global Circular Queue Implementation in C
#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) {
@Ch-sriram
Ch-sriram / area-container-max.cpp
Last active November 1, 2020 19:51
Area of Container with the Most Amount of Water [TC: O(N); SC: O(N)]
// 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;
@Ch-sriram
Ch-sriram / 3sum-closest.cpp
Last active November 1, 2020 13:07
3Sum Closest [TC: O(N^2); SC: O(1)]
// 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
@Ch-sriram
Ch-sriram / cycle-undirected-dfs.cpp
Last active May 9, 2024 04:59
Detect Cycle in an Undirected Graph [TC: O(V+E); SC: O(V)]
// 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>
@Ch-sriram
Ch-sriram / forest-graph-or-not.cpp
Created October 31, 2020 22:36
Check if Graph is Forest or Not [TC: O(V+E); SC: O(V)]
// 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]) {
@Ch-sriram
Ch-sriram / path-in-graph.cpp
Created October 31, 2020 21:46
Path in a Graph
// 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])
@Ch-sriram
Ch-sriram / dfs-graph.cpp
Created October 31, 2020 20:25
DFS of Graph [TC: O(V+E); SC: O(V)]
// 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])
@Ch-sriram
Ch-sriram / connected-components-dfs.cpp
Created October 31, 2020 20:02
Number of Connected Components [TC: O(V+E); SC: O(V)]
#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);
@Ch-sriram
Ch-sriram / bfs-graph.cpp
Created October 31, 2020 17:48
BFS of Graph [TC: O(V+E); SC: O(V)]
// 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;