Skip to content

Instantly share code, notes, and snippets.

View sdmcraft's full-sized avatar

Satya Deep Maheshwari sdmcraft

View GitHub Profile
import java.util.ArrayList;
import java.util.List;
class Solution {
public boolean canFinish(int numTasks, int[][] prerequisites) {
...
for (int i = 0; i < numTasks; i++) {
if (adjacencyList[i] != null) {
return false;
}
}
import java.util.ArrayList;
import java.util.List;
class Solution {
public boolean canFinish(int numTasks, int[][] prerequisites) {
List<Integer>[] adjacencyList = new ArrayList[numTasks];
int[] prereqCount = new int[numTasks];
for (int i = 0; i < prerequisites.length; i++) {
if(adjacencyList[prerequisites[i][1]] == null) {
adjacencyList[prerequisites[i][1]] = new ArrayList<>();
}
@sdmcraft
sdmcraft / StreamProcessor.js
Created April 4, 2025 04:44
A toy example to explain stream processing paradigm
class Stream {
constructor() {
this.source = []; // Queue to hold incoming events
this.operations = []; // List of transformations (filter, map)
this.reduction = null; // Stores reduction function (if any)
this.isProcessing = false; // Prevents duplicate processing
this.totals = {}; // Object to track totals by category
}
/**
@sdmcraft
sdmcraft / restaurant-cqrs-cdc.js
Last active April 7, 2025 12:06
Understanding CQRS and CDC: A Practical Guide with Real-World Analogies
/**
* Restaurant CQRS and CDC Example
*
* This file demonstrates the Command Query Responsibility Segregation (CQRS)
* and Change Data Capture (CDC) patterns using a restaurant analogy.
*/
// ===== Event Emitter (simulating a message bus) =====
const EventEmitter = require('events');