Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
// N queens class Solution { public: bool isSafe(int row , int col ,vector
board , int n ) { int checkr = row ; int checkc = col ; while( checkr >=0 && checkc>=0) { if(board[checkr][checkc]=='Q') { return false ; } checkr --; checkc --; } int tc = col ; while(tc>=0) { if(board[row][tc]=='Q') { return false ; } tc--; } checkr = row ; checkc = col ; while( checkr
=0) { if(board[checkr][checkc]=='Q') { return false ; } checkr ++; checkc --; } return true ; } void solve(int col ,vector
&board , vector
> &answer , int n ) { if (col == n ) { answer.push_back(board) ; return ; } for(int row =0 ; row
> solveNQueens(int n) { vector
> answer ; vector
board(n) ; string s(n , '.') ; for(int i = 0 ; i
v1 , vector
v2 ) { if (v1[1] == v2[1]) return v1[0]
>& intervals) { sort(intervals.begin(), intervals.end(), compare); int i = 0 ; int j = 1 ; int c = 1 ; int n = intervals.size(); while(j
#include
using namespace std; class Solution { public: int solve(string s1, string s2, int i, int j, vector
>& vec) { if (i == s1.length() || j == s2.length()) { return 0; } if (vec[i][j] != -1) { return vec[i][j]; } int ans = 0; if (s1[i] == s2[j]) { ans = 1 + solve(s1, s2, i + 1, j + 1, vec); } else { ans = max(solve(s1, s2, i + 1, j, vec), solve(s1, s2, i, j + 1, vec)); } return vec[i][j] = ans; } int longestCommonSubsequence(string text1, string text2) { int rows = text1.length(); int cols = text2.length(); vector
> vec(rows, vector
(cols, -1)); return solve(text1, text2, 0, 0, vec); } }; //eulers #include
#include
#include
bool iscyclicBFS(int src, unordered_map
&visited, unordered_map
> adj){ unordered_map
parent; parent[src]=-1; visited[src]=1; queue
q; q.push(src); while(!q.empty()){ int front = q.front(); q.pop(); for(auto neighbour: adj[front]){ if(visited[neighbour]==true && neighbour!=parent[front]){ return true; } else if(!visited[neighbour]){ q.push(neighbour); visited[neighbour]=1; parent[neighbour]=front; } } } return false; } bool iscyclicDFS(int node,int parent, unordered_map
&visited, unordered_map
> &adj){ visited[node]=true; for(auto neighbour: adj[node]){ if(!visited[neighbour]){ bool cycledetected=iscyclicDFS(neighbour, node,visited,adj); if(cycledetected) return true; } else if(neighbour != parent){ //cycle present return true; } } return false; } string cycleDetection (vector
>& edges, int n, int m) { // create adjacency list unordered_map
> adj; for(int i=0;i
visited; for(int i=0;i
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)