Add Two Numbers II in C++

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

375 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

320 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

How to 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

371 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

How can we Implement a 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

How can we Implement a 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

7K+ 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

C++ Array of Strings

Farhan Muhamed
Updated on 21-Jul-2025 19:04:39

20K+ Views

A string is a sequence of characters used to store information as text. In C++, strings are represented as array of characters using the std::string class. In this article, we will learn what is an array of strings in C++, how to declare and initialize it, and how to access its elements. C++ Array of Strings Array of strings refer to an array where each element is a string. Just like a normal array, we can define an array of strings by specifying the data type as std::string and the size of the array inside square brackets. To initialize ... Read More

Array Manipulation and Sum using C/C++

Farhan Muhamed
Updated on 21-Jul-2025 19:00:29

3K+ Views

In this problem, you are given an integer array arr of size n and an integer S. Your task is to find an element k in the array such that if all the elements greater than k in the array are replaced with k, then the sum of all the elements of the resultant array becomes equal to S. If such an element exists, print it; otherwise, print -1. Scenario 1: Input: int S = 9; int arr[] = { 1, 3, 2, 5, 8 }; Output: ... Read More

Array sum in C++ STL

sudhir sharma
Updated on 21-Jul-2025 18:59:36

37K+ Views

The array sum refers to the sum of all elements in an array. The STL library of C++ provides built-in functions to easily calculate the sum of elements in an array. In this article, we will explain all those STL functions with examples. Consider the following input/output scenario to understand the concept of array sum: Input: int arr[] = {1, 2, 3, 4, 5}; Output: 15 Explanation: The sum of the elements in the array is 1 + 2 + 3 + 4 + 5 = 15. Following are the different STL functions ... Read More

Advertisements