Suppose we have given K eggs, and we have a building with N floors from 1 to N. Now each egg is identical in function, and if an egg breaks, we cannot drop it again.There exists a floor F with between 0 and N such that any egg dropped at a floor higher than F will break, and any egg dropped at or below floor F will not break. In each move, we may take an egg and drop it from any floor X. The X is in range 1 to N.Our goal is to know with certainty what the ... Read More
A number is said to be a magical number, if that number is divisible by A or B. We have to find the Nth magical number. As the answer may very large, we will return it modulo 10^9 + 7.So, if the input is like N = 4, A = 4, B = 3, then the output will be 8To solve this, we will follow these steps −Define a function cnt(), this will take x, A, B,return (x / A) + (x / B) - (x / lcm of A and B)From the main method, do the following −l := 2, r := 1^14, ret := 0while l
Suppose there is a car, that travels from a starting position to a destination which is t miles east of the starting position.Now along the way, there are many gas stations. So each station[i] represents a gas station that is station[i][0] miles east of the starting position, and that station has station[i][1] liters of gas.If the car starts with an infinite size of gas tank, which initially has startFuel liters of fuel in it. It uses 1 liter of gas per 1 mile that it drives.When the car reaches one gas station, it may stop and refuel, so now it ... Read More
Suppose we have an array A. We have to find the length of the shortest, non-empty, contiguous subarray of A whose sum is at least K. If there is no such subarray, then return -1.So, if the input is like [5, 3, -2, 2, 1] and k = 6, then the output will be 2, as we can see (5+3) >= 6To solve this, we will follow these steps −n := size of Aans := n + 1, j := 0, sum := 0Define one deque dqfor initialize i := 0, when i < n, update (increase i by 1), ... Read More
Suppose there are N workers. Each worker has the quality parameter. The i-th worker has a quality[i] and a minimum wage expectation wage[i]. Now we want to hire K workers to form a paid group. When we are hiring a group of K workers, we must pay them according to the following rules −Each worker in the paid group should be paid in the ratio of their quality by comparing with others in the paid group.Every worker in the paid group must be paid at least their minimum wage expectation.We have to find the least amount of money needed to ... Read More
The autofocus attribute is a boolean attribute. When present, it specifies that an element should automatically get focus when the page loads. An example is given below First Name: Last Name:
HTML is expressed as SGML and XHTML is expressed in XML. Creating XHTML is connected with more restrictions in the form of markup.Avoid using the or tags in XHTML 1.0 Transitional, as those are not an element of that specification.Convert from HTML to XHTMLAdd an XHTML to the first line of every pageAdd a xmlns attribute to the HTML element of every pageChange all element names to lowercaseClose all empty elementsChange all attribute names to lowercaseQuote all attribute values
Suppose we have two strings A and B. These two strings are K-similar (where K is one nonnegative integer) if we can swap the positions of two letters in A exactly K times so that the resulting string is B. So, we have two anagrams A and B, we have to find the smallest K for which A and B are K-similar.So, if the input is like A = "abc", B = "bac", then the output will be 2.To solve this, we will follow these steps −Define a function swapp(), this will take string s, i, j, x := s[i], ... Read More
Suppose we have one undirected, connected graph with N nodes these nodes are labeled as 0, 1, 2, ..., N-1. graph length will be N, and j is not same as i is in the list graph[i] exactly once, if and only if nodes i and j are connected. We have to find the length of the shortest path that visits every node. We can start and stop at any node, we can revisit nodes multiple times, and we can reuse edges.So, if the input is like [[1], [0, 2, 4], [1, 3, 4], [2], [1, 2]], then the output ... Read More
Suppose we have two strings X and Y, these are similar if we can swap two letters of X, so that it equals Y. Also two the strings X and Y are similar if they are equal. As an example, consider, two strings are like "tars" and "rats" are similar, if we swap t and r, then we can find another, now "rats" and "arts" are similar, but "star" is not similar to "tars", "rats", or "arts". Now we can see, these form two connected groups by similarity: {"tars", "rats", "arts"} and {"star"}. Here "tars" and "arts" are in the ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP