Fading Coder

One Final Commit for the Last Sprint

String Manipulation: Reversing Words and String Rotation with O(1) Space Complexity

This article covers two classic string manipulation problems that demonstrate the power of in-place operations and the three-step reverse technique. We'll also introduce the KMP algorithm for pattern matching. 151. Reverse Words in a String String manipulation in C++ offers a significant advantage o...

Detecting and Listing Gaps in a Daily Schedule

Given a list of scheduled time intervals with in a 24-hour period, the goal is to identify and output the time ranges that are not covered by any of the provided intervals. Input Format The first line contains an integer N, rerpesenting the number of schedulde intervals. The following N lines each c...

Understanding Value Categories and Move Semantics in Modern C++

Value categories in C++ dictate how expressions interact with memory and how the compiler handles assignments and functon calls. Understanding the distinction between lvalues and rvalues is fundamental to mastering modern C++ resource management and template metaprogramming. Lvalues and Rvalues An l...

Understanding Encapsulation in C++ through Access Control and Member Functions

Encapsulation combines data and the methods that operate on that data into a single unit, representing real-world entities. It also enforces controlled access to these internal components. In C++, this unit is called a class. For example, we can design a Circle class to calculate its circumference....

Polygon Perimeter Calculation via Inheritance

Givan the base class framework for polygons: class polygon { protected: int number; // Number of sides, at most 100 private: int side_length[100]; // Array of side lengths public: polygon(); // Constructor can be overloaded as needed int perimeter(); // Calculate polygon perimeter void display(); //...

Dynamic Programming for Maximum Stock Profit: Single and Multiple Transactions

Valid for a single buy-sell cycle The problem asks for the maximum possible profit from one purchase and one sale. A dynamic programming approach tracks two states for each day: cash_with_stock[i]: the largest amount of cash achievable on day i while holding the stock. cash_without_stock[i]: the lar...

Understanding Classes, Objects, and Member Functions in C++

In C++, a class keyword is used to define a blueprint for creating objects. The class name follows the class keyword, and the class body is enclosed in curly braces {}. A semicolon ; must terminate the class definition. Elements within the class body are called members. Variables declared inside a c...

Singleton Pattern Implementation in C++

Singleton Pattern Fundamentals The Singleton pattern ensures a class has only one global instance while providing controlled access to it. This pattern is suitable for scenarios requiring centralized management of shared resources or global configuration settings. Lazy Initialization Approach class...

Implementing the Prototype Pattern in C++: Shallow vs. Deep Copying

The Prototype patern is a creational design pattern used to create new objects by copying an existing instance, known as the prototype. In C++, this is typically achieved through copy constructors. When dealing with classes that manage dynamic memory, it is crucial to understand the distinction betw...

Working with Annotations and Decorative Items in QCustomPlot

What are Abstract Items? When visualizing data, we often focus on the primary graph types like bar charts, pie charts, or splines. However, a chart's effectiveness relies heavily on auxiliary elements that provide context, such as axes, grid lines, legends, and annotations. In QCustomPlot, these sup...