Additive Number in C++

Nishu Kumari
Updated on 28-Jul-2025 19:30:40

694 Views

We are given a string containing only digits from 0 to 9, and we need to check whether it is an additive number. An additive number is a string that can form an additive sequence, where each number (starting from the third) is the sum of the previous two. For the sequence to be valid, it must have at least three numbers. Let's look at the example scenarios to understand the problem clearly: Scenario 1 Input: "112358" Output: true Explanation: The digits can form the sequence: 1, 1, 2, 3, 5, 8 Here, 1 + 1 = 2 1 ... Read More

Alternate Bits of Two Numbers to Create a New Number in C++

Nishu Kumari
Updated on 28-Jul-2025 19:26:34

248 Views

Here, we are given two numbers, and we have to create a new number by combining their bits in an alternating way. We take the first bit from the second number, the second bit from the first number, the third bit from the second again, and so on. We start from the least significant bit and continue until all bits from both numbers are used. Let's look at a few example scenarios to understand the problem clearly: Scenario 1: Input: First_number = 8, Second_number = 9 Output: 9 Explanation: Binary of 8 = 1000, Binary of 9 = ... Read More

Create Septet Tuple in Java

Alshifa Hasnain
Updated on 28-Jul-2025 19:20:03

163 Views

Java does not have built-in tuple support; to use the tuple, we use the third-party library called Javatuples. This library provides classes representing fixed-size tuples of different sizes. The Septet class is one of these classes that represents a tuple with 7 values. Creating a Septet Tuple in Java We can create a Septet in Java in the following ways: Using a Constructor Using fromCollection() method Using with() method Using fromArray() method Using a Constructor The constructor of the Septet class ... Read More

Iterate Over a TreeMap in Java

Aishwarya Naglot
Updated on 28-Jul-2025 18:51:44

3K+ Views

TreeMap is based on the Red-Black tree structure, which is a It is a part of the Java Collections Framework. It is a sorted map and maintains the order of its keys. Its order depends on the natural ordering of the keys or by a Comparator.Since the TreeMap is not a Collection, we cannot use the for-each loop to iterate through it. Instead, we can use the entrySet() method to get a set view of the mappings contained in the map, which we can then iterate over to access the keys and values. Let's explore some scenarios to understand the ... Read More

Area of the Largest Triangle Inscribed in a Hexagon in C++

Ravi Ranjan
Updated on 28-Jul-2025 17:57:50

397 Views

In this problem, our task is to find the area of the largest triangle that can be inscribed in a regular hexagon. Each side of the hexagon and triangle is of length a and b, respectively. Area of the Largest Triangle Inscribed in a Hexagon You can calculate the area of the largest triangle inscribed in a regular hexagon using the following formula: $$ Area\ of\ triangle\ inside\ hexagon\ = \frac{3\sqrt{3}}{4} \cdot a^2 $$ Derivation The first step is to establish a relation between a and b, as the value of a(side of the hexagon) is ... Read More

Iterate HashSet in Java

Aishwarya Naglot
Updated on 28-Jul-2025 16:09:59

3K+ Views

The HashSet class is a part of the Java Collections Framework, and it implements the Set interface. It is a collection of unique individual elements. It internally uses a hash table; therefore, the iteration order of elements is not guaranteed. Our task is to iterate through the elements of a HashSet in Java. Let's look at some scenarios to understand the problem better: Scenario 1 Input: {1, 2, 3, 4, 5} Output: 1 2 3 4 5 Explanation: The HashSet contains the elements 1, 2, 3, 4 Scenario 2 Input: {8, 3, 5, 1, 9} Output: 8 3 5 1 ... Read More

Create Pair Tuple in Java

Alshifa Hasnain
Updated on 28-Jul-2025 15:29:41

356 Views

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 Sextet: 6-element tuple ... Read More

Iterate Through ArrayList in Java

Aishwarya Naglot
Updated on 28-Jul-2025 15:18:30

7K+ Views

ArrayList is a part of the Java Collections Framework. It is used to store elements in a dynamic array that can grow as needed. Unlike arrays, ArrayLists can change their size dynamically, which makes them easier for storing collections of objects without fixing the size at the time of creation. Our task is to iterate through an ArrayList in Java. Let's look at some scenarios to understand the problem better: Scenario 1 Input : [1, 2, 3, 4, 5] Output: 1 2 3 4 5 Explanation: We will iterate through the ArrayList and print each element. Scenario 2 Input ... Read More

Common Errors in C and C++

Tapas Kumar Ghosh
Updated on 28-Jul-2025 15:15:22

13K+ Views

In C/C++, an error occurs due to an invalid operation performed by the user. The error normally stops the program execution until it is fixed. So, the error should be removed before compilation and execution. Types of Error in C/C++ Following is the list of errors occur in C/C++ programming: Syntax Error Run-Time Error Linker Error Logical Error Semantic Error In this article, we will see the implementation of error in C/C++ programs. Syntax Error The syntax error ... Read More

Iterate Through Elements of Java LinkedHashSet

Aishwarya Naglot
Updated on 28-Jul-2025 14:58:13

438 Views

LinkedHashSet is a part of Java's Collection Framework. It is a type of Set that keeps the order of elements the same as they were added. It uses a combination of a hash table and a linked list to store elements.Our task is to traverse/iterate through the elements of a LinkedHashSet in Java. Let's look at some scenarios to understand the problem better: Scenario 1 Input: {1, 2, 3, 4, 5} Output: 1 2 3 4 5 Explanation: The LinkedHashSet contains the elements 1, 2, 3, 4, and 5. When we iterate through it, we get the elements in the ... Read More

Advertisements