Array product in C++ using STL

Farhan Muhamed
Updated on 21-Jul-2025 18:54:59

339 Views

The product of an array refers to the multiplication result of all the elements in the array. The STL library of C++ provides several built-in functions to quickly calculate product of 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 product: // Input array int arr[] = {1, 2, 3, 4, 5}; // Output 120 Explanation: The product of the elements in the array is 1 * 2 * 3 * 4 * 5 = 120. Following ... Read More

3Sum Smaller in C++

Akansha Kumari
Updated on 21-Jul-2025 18:50:37

400 Views

The 3Sum Smaller is one of the problem variations in which we need to find the number of triplets in an array such that their sum is less than a 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 triplets (i, j, k) where i, j, k are indices of an array all in range 0 to n – 1, such that they satisfy the condition: nums[i] + nums[j] + nums[k]

Add all the elements from a collection to the HashSet in Java

Aishwarya Naglot
Updated on 21-Jul-2025 15:24:12

539 Views

HashSet in Java implements the Set interface, which belongs to the Java Collections Framework and is a part of the java.util package. It stores unique elements, which means we cannot store any duplicate (appearing more than once) values in a HashSet. The given task is to add all the elements of another collection to a HashSet object in Java. For example, if we have a collection ArrayList with elements [1, 3, 4, 5, 5]. Our task is to add all these elements to a HashSet, maybe to remove duplicates from the list, or for any other reason. Adding Elements from ... Read More

Add elements at beginning and end of LinkedList in Java

Aishwarya Naglot
Updated on 21-Jul-2025 14:34:34

3K+ Views

In general, a linked list is a linear data structure that is a collection of "nodes". Each node contains data and a pointer pointing to the next node. A doubly linked list contains an extra pointer pointing to the previous node, and using this, we can traverse forwards as well as backwards. LinkedList in Java In Java, a linked list is represented by the class named LinkedList. It is a part of the Java Collection Framework, and it belongs to the java.util package. This class implements two interfaces, namely, List and Deque. In this article, we will learn how to ... Read More

Add elements at the middle of a Vector in Java

Aishwarya Naglot
Updated on 21-Jul-2025 12:21:00

540 Views

In Java, Vector is a part of the Java Collections Framework that implements a growable array of objects, which changes its size. It is thread-safe, so it can be useful in multi-threaded environments. Add elements at the middle of a Vector in Java We can add elements in the middle of a Vector in Java in the following ways: Using add() method Using insertElementAt() method Using add() Method The add() method of the java.util.Vector class accepts an integer value representing an index and an element as parameters and adds the ... Read More

Add elements to HashSet in Java

Aishwarya Naglot
Updated on 21-Jul-2025 11:49:27

397 Views

The java.util.HashSet class is a part of the Java collection framework. It stores unique elements, which means we cannot store the same element more than once. A HashSet can contain only one null value. If we try to add duplicate elements to a HashSet object, the elements will not be added. Adding elements to HashSet in JavaThe following are the methods used to add elements to an existing HashSet object: Using add() method Using Collections.addAll() method Using add() Method The add() method of the HashSet class is used for adding ... Read More

Add months to current date using Calendar.add() method in Java

Aishwarya Naglot
Updated on 21-Jul-2025 11:31:51

5K+ Views

The given task is to add months to a date (object) using the add() method of the Calendar class. For example, if we need to add 5 months to the date: 26-06-2025, the new date would be 26-11-2025. Calendar.add() method in Java The calender.add() method in Java is used to add a specified amount of time to any field of the Calendar. Using this method, we can add months, years, days, etc. This method accepts two parameters: the first one is the field we want to add to, and the second one is the amount we want to ... Read More

Add elements to HashMap in Java

Aishwarya Naglot
Updated on 21-Jul-2025 11:17:08

7K+ Views

HashMap is a part of the Java Collections Framework, it is available in java.util package. It implements the Map interface, and it is used for storing two values at a time: a key and a value. The HashMap key is used to access the associated value. A Java HashMap is similar to a dictionary, where we have a word (key) and its meaning is considered as a value. In this article, we will learn how to add elements to a HashMap in Java Programming. The following are the ways to add elements to a HashMap in Java: Using ... Read More

Add an element to a Stack in Java

Aishwarya Naglot
Updated on 21-Jul-2025 11:05:03

4K+ Views

A stack in Java is a data structure that is used for storing elements. It follows the LIFO (Last In, First Out) principle. If we add an element to the stack last, it will be added at the top of the stack (thus it will be the first one to be picked). If we add another element to the stack, the previously added element will be pushed down, and the new element will be added at the top. We can not access previously added elements until we remove the top element.Add an Element to a Stack in Java In ... Read More

A C Puzzle in C Programming?

Akansha Kumari
Updated on 18-Jul-2025 16:03:43

1K+ Views

C programming puzzles are small but tricky coding problems, which are designed to challenge and to understand the C programming language in a better way. Problem Statement We are given two numbers, and our task is to combine them in such a way that the second integer is placed before the first integer, resulting in a single combined integer. But here, we are not allowed to use any logical, arithmetic, string-related operations, or any pre-defined functions. Consider the following input/output scenarios to understand the puzzle statement better: Scenario 1 Input: 12, 54 Output: 5412 Explanation: Here, the second ... Read More

Advertisements