Skip to content

Instantly share code, notes, and snippets.

View sudipp's full-sized avatar
🎯
Focusing

Sudip Purkayastha sudipp

🎯
Focusing
View GitHub Profile
public Node Connect(Node root) {
Node rootPointer = root;
//maintain 2 pointers
Node childHead = null; //NEXT level's head pointer
Node child = null; //NEXT level's traversal pointer
while (root !=null )
{
private static int CoverLogic(TreeNode node, Stack<TreeNode> stack, HashSet<TreeNode> covered, int minCamera)
{
//if node has any uncovered child, then cover it and it's parent(if any)
if ((node.left != null && !covered.Contains(node.left)) || (node.right != null && !covered.Contains(node.right)))
{
minCamera++;
covered.Add(node);
if (stack.Any()) //has parent
{
public class Solution {
public int[] FindRedundantDirectedConnection(int[][] edges)
{
/*
Step 1. Build In and Out Degree map, detect if any any vertex with Multiple parents.
Step 2. If we don't find vertex 'A' with multiple parents
2.1) Start at 'root' and detect any cycle with DFS, return the edge causing the cycle
Step 3. If we find vertex 'A' with multiple parents
3.1) if out degree at vertex 'A' is > 0, i.e there is a edge going out of the 'A' vertex
3.1.1) Start at 'A' and detect any cycle with DFS, return the edge causing the cycle
@sudipp
sudipp / usb-drive-util-test.js
Created January 15, 2019 21:51
usb-drive-util-test.js
const drives = require('../src/drives').Drives;
function loadUSBDrvList(){
drives.loadUSBDriveDetails().then(function(result){
if(result && result.length== 0){
console.log('No USB drive found in the system');
return;
}
let _ = require('lodash');
const uriTokenizer = require('../utils/uriTokenizer');
const tokenizer = new uriTokenizer( { algorithm: 'RS256', expiresIn : '15m' }, { algorithms: ['RS256'] });
const media = require('../Model/Media');
async function buildMediaFileDownloadUrl(req, mediafile){
let uri= req.protocol + '://' + req.get('host') + '/file/' + (mediafile || "").replace(/^\//, '');
return await tokenizer.signUri(uri, { divison : "Honda"});
}
const fs = require('fs');
const config = require('../assets/configs/config');
const jwt = require('jsonwebtoken');
const urlBuilder = require('build-url');
//We use Public/Private key, but you can use Secret (with HMAC algorithm)
let secretOrPrivateKey = fs.readFileSync(config.sslPrivatekey_path);
let secretOrPublicKey = fs.readFileSync(config.sslPublickey_path);
function uriTokenizer(signOptions, verifyOptions){