Suppose, we have an array called nums and we have to find the number of swaps needed to make nums sorted in any order, either ascending or descending.So, if the input is like nums = [2, 5, 6, 3, 4], then the output will be 2 because initially nums has [2, 5, 6, 3, 4]. If we swap numbers 6 and 4, the array will be [2, 5, 4, 3, 6]. Then, if we swap the numbers 5 and 3, the array will be [2, 3, 4, 5, 6]. So 2 swaps are needed to make the array sorted in ... Read More
Suppose we have to find an array of size N such that the absolute difference between every two consecutive digits is K. Every number in the answer must not have leading zeros except for the number 0 itself.So, if the input is like N = 4 K = 7, then the output will be [1818, 2929, 7070, 8181, 9292], here 0707 is not valid as it has leading 0.To solve this, we will follow these steps −if N is same as 1, thenreturn a new list from range 0 to 9queue := make a queue with all elements from 1 ... Read More
Suppose we have three values, n, index and maxSum. Consider an array called nums we have to find nums[index] and nums satisfies the following conditions −size of nums is nAll elements in n is positive.|nums[i] - nums[i+1]|
Suppose there are m boys and n girls, and m = n. There is a party incoming, and each boy has to go with a girl to that party. So, the boys invite all the girls and a girl can accept one invitation only. We have to find out the total number of invitations from the boys that the girls can accept. The input is given in a m x n matrix, where each cell position i, j denotes if the boy i has sent a letter to girl j. If a cell is 1 it means that an invitation ... Read More
Suppose we have an array nums, we have to partition it into two different subarrays called left and right such that −Each element in left subarray is less than or equal to each element in right subarray.left and right subarrays are non-empty.left subarray has the smallest possible size.We have to find the length of left after such a partitioning.So, if the input is like nums = [5, 0, 3, 8, 6], then the output will be 3 because left array will be [5, 0, 3] and right subarray will be [8, 6].To solve this, we will follow these steps −mx ... Read More
Suppose we have an array called coins with n elements, and it is representing the coins that we own. The value of the ith coin is denoted as coins[i]. We can make some value x if we can select some of our n coins such that their values sum up to x. We have to find the maximum number of consecutive values that we can get with the coins starting from and including 0.So, if the input is like coins = [1, 1, 3, 4], then the output will be 10, because0 = []1 = [1]2 = [1, 1]3 = ... Read More
Suppose we are given two strings, both made of lowercase alphabets. We have to find out the number of quadruples (p, q, r, s) satisfying the given conditions −0
Suppose, we are given two lists; 'phrases' that contain a few selected phrases and 'sentences' that contain several sentences that may or may not contain the phrases from the other list. We have to find out if the various phrases in the first list appear in the second list and sort the first list phrases based on their appearances in the second list. We return the sorted list 'phrases' as output.So, if the input is like phrases = ['strong', 'durable', 'efficient'], sentences = ['the product is durable and efficient', 'strong and durable', 'it is efficient', 'like it because it is ... Read More
Suppose, we are provided with an array that contains the heights of different buildings. The buildings are located on a line, and a building has a better view if it is not obstructed by another taller building. So provided the array containing heights, we have to find out the buildings that do not have other taller buildings to obstruct the view from them. The indices are returned from the array that satisfies the criteria.So, if the input is like height = [5, 6, 8, 7], then the output will be [2, 3]. The buildings in array index 0 and 1 ... Read More
Suppose, we are asked to design a queue that moves the most recently used element to the end of it. The queue will be initialized with integer numbers 1 to n. Now we have to build a function so that whenever it is called, it moves the value from the position given as its input to the end of the queue. We will call the function multiple times, and the function will return the value currently at the end of the queue while performing its moving task.So, if the queue is initialized with a value n = 5, or it ... Read More
 Data Structure
 Networking
 RDBMS
 Operating System
 Java
 iOS
 HTML
 CSS
 Android
 Python
 C Programming
 C++
 C#
 MongoDB
 MySQL
 Javascript
 PHP