Suppose we have an array if equations that represent relationships between variables, now each string equations[i] has the length 4 and takes one of two different forms: "a==b" or "a!=b". Here, a and b are lowercase letters, that are representing one-letter variable names. So we have to find true if and only if it is possible to assign integers to variable names so as to satisfy all the given equations.If the input is like: ["a==b", "b==c", "a==c"], then the answer will be true.To solve this, we will follow these steps −Define a method called getParent(), this will take character x ... Read More
Suppose we have two integers A and B, we have to return any string S, such that −S has length A + B and contains exactly A number of letter ‘a’ and B number of ‘b’ letters.Substring “aaa” and “bbb” will not be in the string SSo if the given integers are A = 4, B = 1, then the result will be “aabaa”.To solve this, we will follow these steps −Define a string ret, initially this is emptywhile |A – B| >= 2, if A > B, thenret := ret concatenate ‘aa’decrease A by 2if B is non-zero concatenate ... Read More
Suppose we have to make a timebased key-value store class called TimeMap, that supports two operations.set(string key, string value, int timestamp): This will store the key and value, along with the given timestamp.get(string key, int timestamp): This will return a value such that set(key, value, timestamp_prev) was called previously, with timestamp_prev
Consider a subarray A[i], A[i+1], ..., A[j] of A is said to be turbulent when it meets these conditions −For i A[k+1] when k is odd, and A[k] < A[k+1] when k is even;Otherwise, for i A[k+1] when k is even, and A[k] < A[k+1] when k is odd.So the subarray is turbulent if the comparison sign flips between each adjacent pair of elements in the subarray. Now find the length of a maximum size turbulent subarray of A. So if the input is like [9, 4, 2, 10, 7, 8, 8, 1, 9], output is 5. This ... Read More
Suppose we have to find all non-negative integers of length N such that the absolute difference between every two consecutive digits is K. We have to keep in mind that every number in the answer must not have leading zeros except for the number 0 itself. We may return the answer in any order. So if N = 3 and K = 7, then output will be [181, 292, 707, 818, 929], Here we can see 070 is not a valid number, because it has one leading zero.To solve this, we will follow these steps −Create one matrix called dp, ... Read More
Suppose we have an array A of integers, a ramp is a tuple (i, j) for which i < j and A[i]
Suppose there are 8 prison cells in a row, and in each cell there is a prisoner or that is empty. In each day, whether the cell is occupied or vacant changes according to the following rules −If one cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.Otherwise, it becomes empty.We will describe the current state of the prison in the following way: cells[i] will be 1 if the i-th cell is occupied, else cells[i] will be 0.So we have the initial state of the prison, then return the state of the ... Read More
Suppose we have an array of integers A with even length, now we have to say true if and only if it is possible to reorder it in such a way that A[2 * i + 1] = 2 * A[2 * i] for every 0 0, thenif m[key of kv] is not 0 and m[2* key of kv] > 0x := min of m[key of kv] and m[2* key of kv]cnt := cnt – (x * 2)decrease m[2 * key of kv] by xdecrease m[key of kv] by xotherwise when key of kv = 0, thencnt := cnt ... Read More
Suppose we have a deck of cards; every card has a one unique number. We can order the deck in any order that we want. So Initially, all the cards start face down (unrevealed) in one deck. Now, we do the following steps multiple times, until all cards are revealed −Suppose we have a deck of cards; every card has a one unique number. We can order the deck in any order that we want. So Initially, all the cards start face down (unrevealed) in one deck. Now, we do the following steps multiple times, until all cards are revealed ... Read More
Suppose we have an initial power P, an initial score of 0 points, and one bag of tokens. Now each token can be used at most once, there is a value token[i], and has potentially two ways to use it, these are as follows −If we have at least token[i] power, then we may play the token face up, losing token[i] power, and gaining 1 point.Otherwise when we have at least 1 point, we may play the token face down, gaining token[i] power, and losing 1 point.We have to find the largest number of points that we can have after ... Read More
 Data Structure
 Networking
 RDBMS
 Operating System
 Java
 iOS
 HTML
 CSS
 Android
 Python
 C Programming
 C++
 C#
 MongoDB
 MySQL
 Javascript
 PHP