Suppose, we want to make a data structure, that supports some operations, these operations must be preformed in O(1) amount of time. So let these operations are like −insert(x): insert x into the collectionremove(x): delete x from the collectiongetRandom(): This will find random element form that collection.To solve this, we will follow these steps −Make an array numsmake one map mDefine a function insert(), this will take val, ret := when val is not in minsert size of nums at the end of m[val]insert { val, size of m[val] – 1} pair at the end of numsreturn retDefine a function ... Read More
Add the following code snippet to image properties, and prevent images from being dragged and selected.img { user-drag: none; user-select: none; -moz-user-select: none; -webkit-user-drag: none; -webkit-user-select: none; -ms-user-select: none; }On double click on a text or image, it is highlighted (selected). The user select property can be used to prevent this. By setting this property to none, we can prevent our image from being selected (highlighted).ExampleYou can try to run the following code to prevent the image from being selected − img { -drag: none; user-select: none; -moz-user-select: none; -webkit-user-drag: none; -webkit-user-select: none; -ms-user-select: none; }
The refresh button which was until now hidden in the flow menu, has been replaced by pull-down-to-refresh feature in chrome. However, some users do not need this feature in their application.body { // disables pull-to-refresh // allows overscroll glow effects overscroll-behavior-y: contain; }The overscroll behaviour property of CSS disables the pull to refresh action. In the above given code we have fixed double pull to refresh animation in the chatbox demo. The inbox blurs while the entire page is being refreshed.
Suppose we have a 2D matrix, and an integer k. We have to find the max sum of a rectangle in the matrix, such that its sum is not greater than k. So, if the input is like −1010-32And k = 3, then the output will be 3, as the sum of marked rectangle is 3.To solve this, we will follow these steps −Define a function maxSumSubmatrix(), this will take one 2D array matrix and k, n := row number, m := column numberans := -inffor initialize l := 0, when l < m, update (increase l by 1), do ... Read More
Use the onfocus attribute to execute a script when the element gets focus in HTML.ExampleYou can try to run the following code to implement the onfocus attribute − Enter subject name below, Subject: function display(val) { document.getElementById(val).style.background = "blue"; }
Suppose we have some envelops, these envelops has height and width values as pairs. We can put one envelop into another one if the height and width of second envelop both are smaller than the height and width of the first one. So, what will be the maximum number of envelops that we can put inside other. So, if the inputs are like [[5, 5], [6, 4], [6, 8], [2, 3]], then the output will be 3, as smallest envelop is [2, 3], then [5, 5], then [6, 8].To solve this, we will follow these steps −sort the array v ... Read More
Suppose we have an integer array nums, we have to find the number of range sums that lie in range [lower, upper] both inclusive. The range sum S(i, j) is defined as the sum of the elements in nums from index i to index j where i ≤ j.So if the input is like [-3, 6, -1], lower = -2 and upper = 2, then the result will be 2, as the ranges are [0, 2], the sum is 2, [2, 2], sum is -2.To solve this, we will follow these steps −Define a function mergeIt(), this will take array ... Read More
Suppose we have two arrays of length m and n with digits 0-9 representing two numbers. We have to create the maximum number of length k that is less than m + n from digits of the two. We have to keep in mind that the relative order of the digits from the same array must be preserved. We have to find the array of the k digits. So if the inputs are like [3, 4, 7, 5] and [9, 1, 3, 5, 8, 4], and k = 5, then the answer will be [9, 8, 7, 5, 4].To solve ... Read More
Use the target attribute to specify the target for where to open the linked document in HTML. Here are the values of the target attribute −AttributeDescription_blankOpens the linked page in a new tab.selfOpens the linked page in the current tab.parentOpens the linked page in a parent frame.topOpens the linked page in the topmost frame.ExampleYou can try to run the following code to implement target attribute − HTML target attribute References Refer the following website. The above link will open in a new tab.
The translate attribute is useful to set that the content of an element is to be translated or not.The following are the attributes −AttributeValueDescriptionYesThe content should be translated.NoThe content should not be translated.If you did not want a specific word to be translated, then add it to the translate attribute −This won’t get translated.
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP