Suppose we have a positive integer N, we have to find the number of positive integers less than or equal to N that have at least 1 repeated digit .So, if the input is like 99, then the output will be 9, as we have numbers like 11, 22, 33, 44, 55, 66, 77, 88, 99.To solve this, we will follow these steps −Define a function A(), this will take m, n, ret := 1for initialize i := 0, when i < n, update (increase i by 1), do −ret := ret * m(decrease m by 1)return retFrom the main ... Read More
Suppose we have a N x N grid of cells, in each cell (x, y) there is a lamp. Initially, some of the lamps are on. The lamps[i] is the location of the i-th lamp that is on. Each lamp that is on glows every square on its x-axis, y-axis, and both diagonals. Now for the i-th query i.e. queries[i] = (x, y), the answer to the query is 1 if the cell (x, y) is glowed, otherwise 0. After each query (x, y), we turn off any lamps that are at cell (x, y) or are adjacent 8-directionally. Return ... Read More
Suppose we have N piles of stones arranged in a row. Here the i-th pile has stones[i] number of stones. A move consists of merging K consecutive piles into one pile, now the cost of this move is equal to the total number of stones in these K number of piles. We have to find the minimum cost to merge all piles of stones into one pile. If there is no such solution then, return -1.So, if the input is like [3, 2, 4, 1] and K = 2, then the output will be 20, this is because, we will ... Read More
The only access to camera device is not possible in iOS. The official specification suggests the following −A User Agent implementation of this specification is advised to seek user consent before initiating capture of content by microphone or camera. This may be necessary to meet regulatory, legal and best practice requirements related to the privacy of user data. In addition, the User Agent implementation is advised to provide an indication to the user when an input device is enabled and make it possible for the user to terminate such capture.Similarly, the User Agent is advised to offer user control, such ... Read More
Suppose we have an array A of positive integers, we can say that array is squareful if for every pair of adjacent elements, their sum is a perfect square. We have to find the number of permutations of A that are squareful. Two permutations A1 and A2 will not be same if and only if there is some index i such that A1[i] not same as A2[i].So, if the input is like [3, 30, 6], then the output will be 2, as we have two permutations like [3, 6, 30], [30, 6, 3].To solve this, we will follow these steps ... Read More
Suppose we have an array A. This is containing only 0s and 1s, here a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously inverting the bits n the subarray. We have to find the minimum number of K-bit flips required so that there is no 0 in the array. If there is no such possibility, then return -1.So, if the input is like [0, 0, 0, 1, 0, 1, 1, 0] and K = 3, then the output will be 3, as we need to perform the operations three times, on the first try flip ... Read More
Suppose we have an array A of positive integers, we can call a good subarray (contiguous) of A, if the number of different integers in that subarray is exactly K. So, if the array is like [1, 2, 3, 1, 2] has 3 different integers: 1, 2, and 3. We have to find the number of good subarrays of A.So, if the input is like [1, 2, 3, 1, 4] and K = 3, then the output will be 4, as it can form three subarrays with exactly four distinct integers, these are [1, 2, 3], [1, 2, 3, 1], ... Read More
Suppose we have an array of integers A. We have to find the number of triples of indices (i, j, k) such that −0
Suppose we have two strings, these are S and T, each of which represents a positive rational number, We have to check whether they represent the same number or now. The strings may use parentheses to denote the repeating part of the rational number.As we know that rational numbers can be represented using up to three parts: an integer part, a non-repeating part, and a repeating part. The number will be represented in one of the following three ways −Only integer part (like 0, 12, 123)IntegerPart.NonRepeatingPart (like 0.5, 1.0, 2.12, 2.0001)IntegerPart.NonRepeatingPart(RepeatingPart>) (like 0.1(6), 0.9(9), 0.00(1212))For example Both 0.1(6) or 0.1666(6) ... Read More
Suppose we have a positive integer x, we will write an expression of the form x (op1) x (op2) x (op3) x ... where op1, op2, etc. are the operators. And these operators can be either addition, subtraction, multiplication, or division. For example, with x = 3, we might write 3 * 3 / 3 + 3 - 3 which is a value of 3. There are few some rules, these are as follows -The division operator (/) returns rational numbers.There are no parentheses placed anywhere.We use the usual order of operations − multiplication and division has higher priority than ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP