LinkedHashMap is a data structure in Java that is part of the Java Collections Framework. It is very similar to HashMap.It stores key-value pairs, where each key is unique, and it allows null values, but allows only one null key. The main difference is that the LinkedHashMap returns the elements in the order they were inserted. This is because it maintains a linked list with entries in the map, which helps it to retain the insertion order of the elements. Our task is to check if a particular key exists in a LinkedHashMap in Java. Scenario 1 Following is a ... Read More
A string is a sequence of characters, like words, numbers, or sentences, enclosed in double quotes ("). The given task is to add a closed pair of HTML bold tags around a string using C++.Let us understand this with an example: Input: abc Output: abc Add Bold Tag in String in C++ To add bold tags to a string in C++, we use string concatenation. This is the process of joining two or more strings together to form a new string. In C++, this can be done using the '+' operator. To wrap a string with bold ... Read More
Adding two numbers is a basic arithmetic operation, where we simply combine their values to get the total. The given task is to add two numbers using the "++" operator in C++. Let's understand this with an example: Scenario 1 // Adding two numbers using '+' operator Input: a = 7, b = 3 Output: 10 Explanation: a + b => 7 + 3 = 10 Scenario 2 // Adding two numbers using '++' operator Input: a = 7, b = 3 Output: 10 Explanation: a + b => 7 + 1 + ... Read More
The C++ STL or Standard Template Library is a collection of general-purpose classes and functions with templates for implementing many algorithms and data structures such as vectors, lists, queues, and stacks. The 4 components of STL are: Containers, Algorithms, Iterators, and Functors. In this article, we will discuss the functions of the header that work on arrays, and are introduced in C++ 11 and later versions. C++ Header The algorithm header provides various built-in functions that implement algorithms such as searching, sorting, finding the maximum element, etc. These functions perform various operations on containers such ... Read More
In this problem, we have n number of coins. To arrange these coins in a staircase shape such that each row consists of k number of coins, where k is the row number in which the coins are placed. The last row may or may not be completely filled. Our task is to find the number of completely filled rows. Here is a scenario of arranging coins problem: Scenario Input: n = 8 Output: 3 Explanation: In the above figure, we can see there are 3 completely filled rows and the ... Read More
TreeSet is a class in Java that implements the Set interface. It stores unique values in a sorted order. It is similar to HashSet, but the difference is that TreeSet stores elements in a sorted manner, while HashSet does not guarantee any order. Our task is to check if a particular value exists in a TreeSet in Java. We can do this using the following methods: Using contains() Method Using Streams API Using contains() Method The contains() method of the TreeSet class is used for checking if a particular value ... Read More
Pandas is a Python library that is designed for data manipulation and analysis. It provides the two data structures: Series: It is a one-dimensional labelled array (like a column in a spreadsheet). DataFrame: It is a two-dimensional labelled data structure (like a table), allowing storage of multiple columns with different data types. Using Pandas, we can perform complex data manipulations with the help of its powerful data structures. It can work with different file formats like CSV, Excel, etc. In this article, we will learn how to analyze data activity using ... Read More
The Pythagorean primes are prime numbers that can be represented in the form 4n + 1, where n is a non-negative integer. These primes have a special property as they can be expressed as the sum of two square numbers. In other words, a prime number p is called a Pythagorean prime if: p is prime, and p ≡ 1 (mod 4), i.e., when divided by 4, it leaves a remainder of 1. For example: 5 = 4x1 + 1 = 22 + ... Read More
Difference Between Adjacent List Elements The given task is to calculate the difference between the adjacent elements in the given list using Python, i.e, we need to subtract the current element from the next element and repeat this for each element in the list (except the last one). Scenario Following is an example scenario: Input: [10, 15, 12, 18] Output: [5, -3, 6] Explanation: Difference between 15 and 10: 15 - 10 = 5 Difference between 12 and 15: 12 - 15 = -3 Difference between 18 and 12: 18 - 12 = 6 Using List ... Read More
An anagram is a rearrangement of the characters of a word or a phrase to generate a new word, using all the original characters exactly once. For example, thing and night are anagrams of each other. An anagram substring search includes two strings (text, pattern); we need to search the given text for any substring that contains the same characters as the pattern, in any order. Scenario Following is an example scenario: Input: str1="cbaebabacd", str2="abc" Output: [0, 6] Explanation: In this case, The substring "cba" at index 0 is an anagram of "abc". The substring "bac" at index 6 is an ... Read More