Advantages of Vector Over Array in C++

Nishu Kumari
Updated on 23-Jul-2025 17:42:11

421 Views

In C++, both arrays and vectors are used to store elements, but the main difference is that arrays have a fixed size and cannot be changed once initialized. Whereas, vectors are dynamic, i., e we can change their size during runtime. In this article, we'll look at the advantages of using vectors over arrays in C++. Here's how we declare an array and a vector in C++: // Declaring an array int arr[5]; // Fixed-size array of 5 integers // Declaring a vector #include std::vector vec; // Dynamic vector of integers Advantages of ... Read More

What are Type Specifiers in C++

Akansha Kumari
Updated on 23-Jul-2025 15:46:50

3K+ Views

In a statically typed language such as C++, type specifiers are keywords that are used to define the type of data that given variables will hold. There are two types of type specifiers: built-in and user-defined type specifiers. Built-in Type SpecifiersThe built-in type specifiers are the basic and predefined data types provided by C++, such as int, float, char, signed, unsigned, short, long, etc. int myNumber = 42; In this given statement, the "int" is a type specifier, which states that the variable "myNumber" can only store integer values or numeric data types. There exist a lot of built-in type specifiers in C++ ... Read More

4Sum Problem in C++

Akansha Kumari
Updated on 23-Jul-2025 15:44:35

600 Views

4SUM ProblemThe 4Sum is one of the problem variations in which we need to find the number of quadruplets present in the array such that their sum is equal to the given target. We are given an array of n integers called nums and a target value, and we have to find the number of index quadruplets (i, j, k, l) where i, j, k, and l are all indices in the range 0 to n - 1, such that they satisfy the condition: nums[i] + nums[j] + nums[k] + nums[l] = target Scenario 1 Inputs: arr= [-1, 0, 1, 2, ... Read More

Add Two Numbers in C++

Nishu Kumari
Updated on 23-Jul-2025 13:21:11

372 Views

We're given two singly linked lists, where each node stores one digit of a number. The digits are arranged from left to right, just like how we normally write numbers. For example: 7 -> 2 -> 4 -> 3 represents the number 7243. Our task is to add these two numbers and return the sum as a new linked list in the same (left-to-right) order. The input number can contain zeroes at the start, but in the output, there should not be any leading zeros. Let's understand this with a diagram given below - Scenario 1 Input: List 1 ... Read More

Accumulator Battery in Python

Akshitha Mote
Updated on 22-Jul-2025 18:50:00

315 Views

Problem Statement Consider a mobile phone, which is in "eco mode". This mode activates once your battery level reaches 20 percent. In this eco mode, the battery drains two times slower than in normal mode. This means that, in normal mode, if the time consumed by the battery is 1% per minute, then the time taken in eco mode is 1% per 30 seconds (1/2 minute). Scenario Now, when we leave our home, we have 100% of the battery. Then t minutes later we have p percent of battery left. We have to find how many minutes we have until ... Read More

Create Acronyms from Words Using Python

Akshitha Mote
Updated on 22-Jul-2025 18:40:42

3K+ Views

The acronym is an abbreviated version of a sentence, which means it is the short form of the given sentence. It is formed from each word's first character in the given sentence. For example, CPU is an acronym of Central Processing Unit. In this article, we will learn how to create acronyms from words using Python. Scenario Input: my_str = "Automatic Teller Machine" Output: ATM Explanation: Here, the given string “Automatic Teller Machine”, we have created an acronym from it by considering first character of each word. Algorithm to Create Acronyms from Words The following are the steps ... Read More

Absolute Distinct Count in a Sorted Array in C++

Akansha Kumari
Updated on 22-Jul-2025 15:53:47

366 Views

An array is a data structure that is used to store elements of the same data type, where a sorted array, in which the elements are arranged in ascending or descending order. The absolute distinct count gives the count of absolute (non-negative or unsigned) values of distinct (unique) elements present in an array. In this article, we will learn how to find the count of absolute values of all distinct elements in the given sorted array in C++. Consider the following input and output scenarios to under the problem better: Scenario 1 Input: [-5, -2, 1, 2, 5, 5, 6, ... Read More

Implement Stack Using Queue in Java

Vivek Verma
Updated on 22-Jul-2025 12:42:53

1K+ Views

This article will discuss how to implement a Stack using a Queue in Java.  Stack in Java In Java, a Stack is a subclass (child class) of the Vector class, and it represents a LIFO stack of objects, which stands for Last-in-First-Out. The last element added at the top of the stack (In) can be the first element to be removed (Out) from the stack. The following diagram will give you a clear idea about the Stack: Queue in Java In Java, the Queue class extends the Collection interface, and it supports the insert and remove operations using a FIFO, ... Read More

Implement Queue Using Stack in Java

Vivek Verma
Updated on 22-Jul-2025 11:44:33

2K+ Views

This article will discuss how to implement a Queue using a Stack in Java. It will briefly introduce the Queues and Stacks, and provide a suitable example that shows their implementation. Queues in Java In Java, the Queue class extends the Collection interface, and it supports the insert and remove operations using a FIFO (First-in-First-Out). The last element added to the end of the queue can become the first element to be removed from the queue. The following diagram will give you a better understanding of the Queue: Stacks in Java In Java, a Stack is a subclass (child class) ... Read More

Activity Selection Problem

Ravi Ranjan
Updated on 21-Jul-2025 19:07:32

6K+ Views

Activity Selection Problem The activity selection problem is an example of a greedy algorithm where the maximum number of non-overlapping activities are selected from the given activity set. A person can complete one activity at a time. The activities are given in the form of their starting and completion times. In this article, we have an array of integers that stores the starting and completion time of each activity. Our task is to select the maximum number of non-overlapping activities from the given activity array. Scenario An example of the maximum activity ... Read More

Advertisements