-
Basic calculator II
In this post we will discuss https://leetcode.com/problems/basic-calculator-ii/ There are 3 apporaches : 2 stack1 stack0 stack We will go over each 1 by 1. Evaluating Arithmetic Expressions with +, -, *, / Using Two Stacks We want to solve an arithmetic expression that includes operators like +, -, *, and /, without parentheses. A simple…
-
Cycle detection Directed graph BFS
In DFS, cycle detection works because you can track the current recursion path — the exact nodes you’re actively exploring.When you revisit a node in the same path, that’s a back edge, indicating a cycle.But BFS is fundamentally different:BFS explores nodes level by level, not along a single path.It doesn’t maintain a notion of a…
-
Detecting a Cycle in a Directed Graph — A Thoughtful Progression
We are given a directed graph. The task is to detect whether the graph contains a cycle. 🧠 Thought ProcessTo detect a cycle, we start from a node and attempt to traverse through the graph.If during this traversal, we encounter the same node again in the current path, we have detected a cycle. The idea…
-
Counting sub arrays
Counting Subarrays: 🔢 Step 1: Understanding Total SubarraysGiven an array of size n, how many contiguous subarrays can we form? Example: For [1, 2, 3, 4], the subarrays are: 11 21 2 31 2 3 422 32 3 433 44 Total = 10 subarrays. 📘 General RuleIf array size is n, then total subarrays =…
-
Design Pattern CheatSheet
https://docs.google.com/spreadsheets/d/e/2PACX-1vQyOMRgVppwRcD8oFTaqqqXh0etz4NA5wRYrqhncT1Ue_DKliRfPlMfQMHq_r_DmfaZuarAb49fAkjx/pubhtml?widget=true&headers=false Referred from : http://www.lug.or.kr/files/cheat_sheet/design_pattern_cheatsheet_v1.pdf Follow more posts @ https://jdecodes.wordpress.com My design pattern articles :
-
DECORATER Design Pattern
The Decorator pattern allows you to dynamically add new behaviors to objects at runtime without altering their original class. It achieves this by wrapping existing objects in a new “decorator” object. Decorators share the same interface as the objects they wrap, enabling seamless integration and composition of functionalities. Too bookish ?? Lets say you have…
Subscribe
Enter your email below to receive updates.