Initialize a Dynamic Array in C++

Farhan Muhamed
Updated on 16-Jul-2025 16:01:28

3K+ Views

Dynamic arrays are a type of array that can grow or shrink their size as elements are added or removed. They are created using pointers and memory management functions such as new and delete. In this article, we will learn different ways to initialize a dynamic arrays in C++. Here is the list of approaches to initialize a dynamic array in C++: Using new and () Using new and {} Using Loop for Custom Initialization Initializing Dynamic Arrays Using new and () This ... Read More

C++ Program to Implement Kadane's Algorithm

Farhan Muhamed
Updated on 16-Jul-2025 16:00:26

2K+ Views

The Kadane's algorithm is used to find the maximum subarray sum in a given array of integers. This section will explain the Kadane's algorithm with example and C++ implementation. Given an array of integers, our task is to find the maximum possible sum for a subarray using Kadane's algorithm. For example:ScenarioConsider the following example with input/output scenario: Input: [-2, 1, -3, 4, -1, 2, 1, -5, 4] Output: 6 Explanation: The subarray [4, -1, 2, 1] has the largest sum = 6. What is Kadane's Algorithm? Kadane's algorithm is an optimized method to find the maximum ... Read More

Add Tuple to List and Vice Versa in Python

Farhan Muhamed
Updated on 15-Jul-2025 18:33:43

2K+ Views

In Python, both tuples and lists are used to store data in sequence. Python provides built-in functions and operators that allow us to easily add elements of a tuple into a list and elements of a list into a tuple. In this article, we will explain various methods to perform these conversions, along with example codes. Scenario 1 You are given a list and a tuple as input, your task is to add tuple into the list and print the list as output. For example: # Input List and Tuple my_list = [3, 6, 9, 45, 66] my_tup = ... Read More

Sum of the Series 1 + 1 + 2 + 1 + 2 + 3 + ... up to n Terms in C++

Ravi Ranjan
Updated on 15-Jul-2025 18:29:51

1K+ Views

In this article, we are given an integer n. It defines the number of terms in the series: 1/1 + ( (1+2)/(1*2) ) + ( (1+2+3)/(1*2*3) ) + … + up to n terms. Our task is to write a program to calculate the sum of series 1/1 + (1+2)/(1*2) + (1+2+3)/(1*2*3) + … up to n terms. The above series can be represented as: $$ \sum_{k=1}^{n} \frac{\sum_{j=1}^{k} j}{k!} $$ Scenario The following example calculates the sum for the given series up to 4 terms: Input: n ... Read More

Angle Between Hands of a Clock in C++

Ravi Ranjan
Updated on 15-Jul-2025 18:27:16

2K+ Views

In this article, we have values of hours and minutes respectively. Our task is to find a smaller angle formed between the hour and the minute hand. The formula for calculating the angle between them is: angle = |30*h - 5.5min|. Here are some examples given below: Scenario 1 Input: Time = 12:45 Output: 112.5 Explanation: Here, hour = 12, minute = 45 angle = |30*h - 5.5min| = |30*12 - 5.5*45| = |360 - 247| = 112.5 Scenario 2 Input: Time = 10:30 Output: 135 Explanation: Here, hour = 10, minute = 30 ... Read More

C++ Program to Implement Trie

Farhan Muhamed
Updated on 15-Jul-2025 18:04:38

2K+ Views

A Trie, also known as a prefix tree, is used to store and search for large sets of strings. In this section we will discuss all about Trie data structure, its operations, and how to implement it in C++. Trie Data Structure A Trie is a data structure similar to a tree that is used to store a dynamic set of strings. The root node represents an empty string, and each edge represents a character. The path from the root to a node represents a prefix of a string stored in the Trie. The image below show how a ... Read More

Check Multiple Regex Patterns Against Input in Java

Maruthi Krishna
Updated on 15-Jul-2025 17:58:40

5K+ Views

In Java, the strings that are used to find the pattern are known as regular expressions. In this article, we will learn to check multiple regex patterns against an input, and it can be done by using 2 approaches. Using Metacharacter Using the List object Using Metacharacter The meta character "|" in Java regular expressions allows you to match more than one regular expression. For example, if you need to match a particular input text with more than one expression, you need to separate them using the following: exp1|exp2|exp3 Example ... Read More

Count the Number of Columns in a MySQL Table with Java

Alshifa Hasnain
Updated on 15-Jul-2025 17:58:08

424 Views

In this article, we will learn how to count the number of columns in a MySQL table using JDBC. We will be using the ResultSetMetaData to get details of the table by using simple examples. What is ResultSetMetaData? The ResultSetMetaData is an interface that is present in the java.sql package. Using ResultSetMetaData, we can get information about the table, for example, what are the column names of each and every table, and how many columns are there?. To create the object for ResultSet: ResultSet rs=st.executeQuery("Select * from Student"); The executeQuery method writes the records, which are then stored in the ... Read More

Add a Value to Pair Tuple in Java

Alshifa Hasnain
Updated on 15-Jul-2025 17:57:26

1K+ Views

By default, Java does not have built-in tuple support; to use the tuple, we use the third-party library called Javatuples. Using this library, you can create a tuple of different sizes, starting from a single-element tuple, which is the Unit class, up to a ten-element tuple (Decade class). The following is the list of JavaTuples library classes: Unit: 1 element tuple Pair: 2 element tuple Triplet: 3 element tuple Quartet: 4 element tuple Quintet: 5 element tuple ... Read More

Write a Short Literal in C++

Akansha Kumari
Updated on 15-Jul-2025 17:35:04

975 Views

In the following article, we will learn about short literals in C++. In both C and C++, different data types have different literals. A literal is a fixed constant value, which is assigned to the variables of different data types. For example, here is a list of different data types with their literals. Datatypes Literals ... Read More

Advertisements