Skip to main content

Posts

Showing posts from November, 2025

Parentheses matching in C#

C# Bracket Matching Algorithm C# Code: Bracket Matching Algorithm (Stack Implementation) TWrite a function in C# that checks whether a given string has balanced parentheses. The string may contain the characters (, ), {, }, [, ], and For example: - Input: "([{}])" → Output: True - Input: "([ {]})" → Output: False - Input: " ()[]{}" → Output: True using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ParenthesesMatching { public static class BracketMatcher { private static readonly Dictionary < char , char > backets = new () { { '(' , ')' }, { '{' , '}' }, { '[' , ']' } }; private static readonly HashSet < char > openingBrackets = new ( backets . Keys ); private s...

What is SOLID principles?

Introduction to SOLID principles • S : Single Responsibility Principle (SRP) • O : Open-closed Principle (OCP) • L : Liskov substitution Principle (LSP) • I : Interface Segregation Principle (ISP) • D : Dependency Inversion Principle (DIP) Definitions • S: A class should only have a single responsibility, that is, only changes to one part of the software’s specification should be able to affect the specification of the class. • O: Software entities (classes, modules, functions, etc.) should be open for extension but closed for modification • L: Derived classes should be substitutable for their base classes without altering the correctness of the program. • I: Clients should not be forced to depend on interfaces they do not use. Instead of one large interface, prefer many small, role-specific interfaces. • D: High-level modules should not depend on low-level modules; both should depend on abstractions. Abstractions should not depend on details; details should depend on abs...