The HTML DOM Storage key() method is used for returning the key name at a given index in a storage object. The index is passed as a parameter to key() method. The storage object can be a session object or localStorage object.SyntaxFollowing is the syntax for −Storage key() method using localStorage −localStorage.key(index);Storage key() method using sessionStorage −sessionStorage.key(index);Here, index is of type integer representing the key number that you want to get the name for.ExampleLet us look at the example for the Storage key() method − storage key() method example Get the first object key name by clicking on ... Read More
The HTML DOM storage event triggers when there has been a change in the storage area of the window. The storage event is triggered only if the other window makes the storage area change for a window. This event doesn’t bubble and is cancellable too.SyntaxFollowing is the syntax for −window.addEventListener("storage", SCRIPT);ExampleLet us look at an example for the Storage Event − Storage Event Example Create the visit localStorage item by clicking the below button CREATE var y=1; window.addEventListener("storage", DisplayChange); function DisplayEvent(event) { document.getElementById("Sample").innerHTML = "The number of visits has been ... Read More
In this section we will see some examples of code shortening strategy for competitive programming. Suppose we have to write some large amount of codes. In that code, we can follow some strategy to make them more short.We can change the type-name to make it short. Please check the code to get the ideaExample Code#include using namespace std; int main() { long long x = 10; long long y = 50; cout
Here we will see one space optimized approach for LCS problem. The LCS is the longest common subsequence. If two strings are “BHHUBC” and “HYUYBZC”, then the length of the subsequence is 4. One dynamic programming approach is already their, but using the dynamic programming approach, it will take more space. We need table of order m x n, where m is the number of characters in first string, and n is the number of characters in the second string.Here we will see how to implement this algorithm using O(n) amount of auxiliary space. If we observe the old approach ... Read More
Suppose we have one graph like below. That graph is Peterson graph. The vertices are numbered from 0 through 9. Each vertex has some letters. Let consider one walk W, in that graph, where L vertices are used. A string S with L letters is realized by the walk W when the letter sequence in W and S are same. We can visit the vertices multiple times.For example, one string S is like “ABBECCD”, this is realized by the walk (0, 1, 6, 9, 7, 2, 3). Our task is to find such walk, and if that walk is present, ... Read More
Suppose we have one integer variable whose size is 4 byte, another pointer variable is there, whose size is 8 bytes. So what will be the output of the following?Example#include using namespace std; main() { int a[4][5][6]; int x = 0; int* a1 = &x; int** a2 = &a1; int*** a3 = &a2; cout
Here we will see one Boolean array puzzle. One array is given with two elements 0 and 1. We have to make all elements to 0. There are some specifications that we should consider −In the array one element is 0, that is fixed, but we do not know what is the position of that elementThe other element can be 0 or 1Only complement operation is allowed here, no other operations cannot be performedWe cannot use branching and loop statementsWe cannot assign 0 directly to the array elementsWe can solve this problem in different ways. There are three of them ... Read More
Here we will see the Osiris number. An Osiris number is such kind of number that are equal to the sum of permutations of sub-samples of their own digits. Suppose the number is 132. Then if we calculate {12 + 21 + 13 + 31 + 23 + 32} this is also 132. So the number is Osiris number. We have to check whether the given number is Osiris number or not.Approach is simple. If we analyze the numbers, each digit is occurring twice so they are in ones position and tens position. So we can check by multiplying 11 ... Read More
push() vs unshift()The methods push() and unshift() are used to add an element in an array. But they have a slight variation. The method push() is used to add an element at the end of the array, whereas the method unshift() is used to add the element at the start of the array. Let's discuss them in detail.push()syntaxarray.push("element");ExampleIn the following example, to a 3 element array, using push() method another element is added at the back of the array and the result is displayed in the output. var companies = ["Spacex", "Hyperloop", "Solarcity"]; ... Read More
Array multiplication we will find the product of all elements of the given array. and then according to the problem, we will divide the product with the number n. let's take an example −Input: arr[] = { 12, 35, 69, 74, 165, 54}; N = 47 Output: 14ExplanationThe array is like {12, 35, 69, 74, 165, 54} so the multiplication will be (12 * 35 * 69 * 74 * 165 * 54) = 19107673200. Now if we want to get the remainder after dividing this by 47 it will be 14.First multiple all the number then ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP