Suppose we have input n, we have to find the largest palindrome that can be made using multiplication of two n digit numbers. As the numbers are very large, we can perform mod using 1337. So if the input is say 2, then the answer will be 987, 987 = (99*91) mod 1337 = 9009 mod 1337 = 987.To solve this, we will follow these steps −maxVal := 10^n – 1minVal := maxVal / 10for initialize h := maxVal, when h > minVal, update (decrease h by 1), do −left := h, right := 0for initialize i := h, when ... Read More
Suppose we have a list of words. These words are distinct. We have to devise an algorithm that will find all concatenated words in the give list of words. A concatenated word is actually a string that is comprised entirely of at least two shorter words in the given array.So if the words are like ["cow", "cows", "cowsgoatcows", "goat", "goatcowsgoat", "hippopotamuses", "deer", "deercowgoatcow"], then the output will be ["cowsgoatcows", "goatcowsgoat", "deercowgoatcow"]To solve this, we will follow these steps −Define a function isPresent(), this will take str, head, idx, an array dp, if idx >= size of str, then −return trueif ... Read More
Suppose there are 1000 buckets, one of them is poisonous, others are filled with water. They all look similar. If a pig drinks the poison it will die within 15 minutes. What will be the minimum amount of pigs that we need to find out the poisonous bucket within one hour?So now consider for the general case and devise an algorithm for this. So, the general case is that If there are n different buckets and a pig drinking poison will die within m minutes, how many pigs are needed to find poisonous bucket within p minutes? There is exactly ... Read More
Suppose we have an array A, where N numbers are present. A subsequence slice of that array is any sequence of integers like (K0, K1, K2, … Kn) such that 0 = 2. So we have to return the number of arithmetic slices.So if the input is like [2, 4, 6, 8, 10], then the answer will be 7, as there are 7 arithmetic slices. [2, 4, 6], [2, 4, 10], [4, 6, 8], [6, 8, 10], [2, 4, 6, 8], [4, 6, 8, 10], [2, 4, 6, 8, 10], To solve this, we will follow these steps −ret := ... Read More
Drawing text in a canvas with a typeface that is loaded via @font-face does not show text correctly at first. This is because the browser has not yet loaded the font from network. Therefore, it makes use of the font, which is already available.The font has to be completed loaded before it is used. This can be ensured using tag. If you want to make sure that the font is available and have some other elements preloaded, then you can do this by using the tag as under You can also load font like this −var newFont = ... Read More
Suppose we have two values n and k. We have to find the lexicographically kth smallest integer in the range of 1 to n. So if the input is like n = 14 and k = 3, then the output will be 11, as the sequence will be [1, 10, 11, 12, 13, 14, 2, 3, 4, 5, 6, 7, 8, 9], then the kth number is 11.To solve this, we will follow these steps −Define a function findKthNumber(), this will take n, k,curr := 1(decrease k by 1)while k is non-zero, do −steps := call the function calcSteps(n, curr, curr + 1)if steps
Suppose we have a string, password. We have to find out minimum changes required to make the password strong. So the password has some following criteria −It must be at least 6 character long and at most 20-character longIt must contain at least one lowercase letter, at least one uppercase letter, and at least one numeric character.It must not contain three repeating characters in a row like …aaa…, …PPP…, …888….So if the input is like "aa26bbb", so we need at least one change, as there is no uppercase letter, and there is three b’s in a row, so we can ... Read More
You can tell your browser not to cache your page by using the following meta tags − In addition, try the following: Append a parameter/string to the filename in the script tag. Change it when the file changes.Then the next time you update the file, just update the version i.e.
Suppose we have an array of positive integers and one value m. We can divide this array into m number of contiguous subarrays. We have to devise an algorithm to minimize the largest sum among these m subarrays.So if the array is say [7, 2, 4, 10, 9], and m = 2, then the sum will be 19, as we can make two subarrays like [7, 2, 4] and [10, 9], then the subarray with largest sum is 19.To solve this, we will follow these steps −Define a function splitArray(), this will take an array v, m, n := size ... Read More
Suppose there is a frog that is crossing a river. The river is divided into x units and at each unit there may be a stone. The frog can jump on a stone, but not water. Here we have a list of stones' positions in sorted ascending order sequence, we have to check whether the frog is able to cross the river by landing on the last stone, or not. Initially, the frog is on the first stone and assume the first jump must be of 1 unit.When the frog's current jump was k units, then its next jump must ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP