Suppose we have a list of pairs of equivalent words synonyms and a sentence text, we have to find all possible synonymous sentences they are sorted lexicographically.So, if the input is like synonyms = [["happy", "joy"], ["sad", "sorrow"], ["joy", "cheerful"]], and text = "I am happy today but was sad yesterday", then the output will be ["I am cheerful today but was sad yesterday", "I am cheerful today but was sorrow yesterday", "I am happy today but was sad yesterday", "I am happy today but was sorrow yesterday", "I am joy today but was sad yesterday", "I am joy today ... Read More
Suppose we have a 2D grid, that represents a campus, there are N workers and M bikes, The value of N
Suppose we have an array of numbers called arr and an integer k. There is a value arr[i] that is said to be stronger than a value arr[j] when |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| is same as the |arr[j] - m|, then arr[i] is said to be stronger than arr[j] if arr[i] > arr[j]. So we have to find a list of the strongest k values in the array.So, if the input is like arr = [1, 2, 3, 4, 5], k = 2, then the ... Read More
Suppose there are n different cities those are numbered from 0 to n-1 and there are also n-1 roads such that there is only one way to travel between two different cities. Suppose the ministry of transport decided to orient the roads in one direction because they are too narrow.Here the roads are represented by connections where connections[i] = [a, b] this represents a road from city a to b.If there is a big event in the capital (city numbered as 0), and many people want to travel to this city. We have to perform some reorienting task on some ... Read More
Suppose we have a rectangular cake with height h and width w, we also have two arrays of integers horizontalCuts and verticalCuts where horizontalCuts[i] represents the distance from the top of the rectangular cake to the ith horizontal cut and similarly, verticalCuts[j] represents distance from the left of the rectangular cake to the jth vertical cut.We have to find the maximum area of a piece of cake after we cut it at each horizontal and vertical position provided in the arrays horizontalCuts and verticalCuts. The answer may be large, so return this modulo 10^9 + 7.So, if the input is ... Read More
Suppose there are a total of n courses we can to take, the courses are labeled from 0 to n-1.Some courses may have direct prerequisites, as example, to take course 0 we have first to take course 1, which is expressed as a pair: [1, 0].So, if we have a number of courses n, a list of direct prerequisite pairs and a list of queries pairs.You should find the answer for each queries[i] whether the course queries[i][0] is a prerequisite of the course queries[i][1] or not. Finally, we have to return a list of boolean, the answers to the given ... Read More
Suppose we have a binary string s and an integer k. We have to check whether every binary code of length k is a substring of s. Otherwise, return False.So, if the input is like S = "00110110", k = 2, then the output will be true. The binary codes of length 2 are "00", "01", "10" and "11". These are present at indices 0, 1, 3, and 2 respectively.To solve this, we will follow these steps −Define one set vtemp := blank stringreq := 2^kfor initialize i := 0, when i < size of s, update (increase i by ... Read More
Suppose we have a binary tree where node values are digits from 1 to 9. One path in the binary tree is said to be pseudo-palindromic when at least one permutation of the node values in the path is a palindrome. We have to find the number of pseudo-palindromic paths going from the root node to leaf nodes.So, if the input is likethen the output will be 2, this is because there are three paths going from the root node to leaf nodes − red path follows [2, 3, 3], the green path follows [2, 1, 1], and the path ... Read More
Here we will see some basic file handling operations in C. The operations are listed below:Writing into a FileReading from FileAppending in a FileWrite into a fileSee the code to get the idea how we write into a fileExample Code#include int main() { FILE *fp; char *filename = "sample.txt"; char *content = "Hey there! You've successfully created a file with content in c programming language."; /* open for writing */ fp = fopen(filename, "w"); if( fp == NULL ) { printf("%s: failed to open. ", filename); return ... Read More
Suppose we have a string s and an integer k. We have to find the maximum number of vowel letters in any substring of s with length k.So, if the input is like s = "abciiidef", k = 3, then the output will be 3To solve this, we will follow these steps −cnt := 0Define one set mfor each vowel v, doinsert v into mret := 0for initialize i := 0, when i < k, update (increase i by 1), do −cnt := cnt + (1 when s[i] is in m, otherwise 0)ret := maximum of ret and cntn := ... Read More