Jun 30, 2021CTCI listHere is the leetcode list for CTCI questions Some questions are not present in the list so I have included them here Leetcode list 👈 Remaining questions Check if a string has all unique characters without using any additional data structure (here) URLify a given string replacing all the spaces in a string with ‘%20 Here we do only need to replace the spaces in between words not the trailing spaces add (2*no_of_spaces) more as 1 space will already be…2 min read
Jun 27, 2021Binary SearchNote : In coding rounds, always use mid= low+(high-low)/2 instead of (low+high)/2 to pass 2 critical test cases else overflow error comes (they genuinely add these cases to test your coding skills You use while (start <= end) if you are returning the match from inside the loop. You use…10 min read
Jun 25, 2021Other Algo’s & conceptsFloyd Warshall (DP) Floyd-Warshall Algorithm is an algorithm for finding the shortest path between all the pairs of vertices in a weighted graph. This algorithm works for both the directed and undirected weighted graphs. …9 min read
Jun 24, 2021Graph Algo’sDijkstra’s shortest path algorithm Relaxation Rule : dist[v] = min( dist[v], (dist[u] + cost[u,v] )11 min read
Jun 24, 2021Some more questionsBipartite graphs If a graph has no cycle or even length cycle then it is Bipartite if cycle length is odd it is not Bipartite If a graph can be colored using 2 colors such that adjacent nodes have different color then we can say that it is Bipartite Formal definition : …6 min read
Jun 22, 2021DFSThe DFS algorithm is a recursive algorithm that uses the idea of backtracking. It involves exhaustive searches of all the nodes by going ahead, if possible, else by backtracking. Stacks are used here (either explicitly or using recursion implicitly) Algorithm: Create a recursive function that takes the index of node…3 min read
Jun 22, 2021Graph RepresentationNote : if no of edges is N & no of vertices is M then if value of nodes are 0-indexed i.e 0,1,2,3,,,, then adjacency matrix and list are of size M+1,N+1 for matrix && N+1 for list else if 1 based indexed then take M,N & N only2 min read
Jun 22, 2021BFSResources Hackerearth , GFG , Leetcode Post COMPLETE BFS (STRIVER YOUTUBE) vector<int>bfsOfGraph(int V, vector<int> adj[]){ vector<int> ans; vector<bool> vis(V, false); queue<int> q; q.push(0); vis[0] = true; while(!q.empty()) { int curr= q.front(); q.pop(); ans.push_back(curr); for(auto it : adj[curr]) { if(!vis[it]) { q.push(it); …7 min read