Suppose we have a digit d, we shall have to convert it into words. So if d = 9, our output should be "Nine". If we provide some d which is beyond the range of 0 and 9, it will return appropriate output.So, if the input is like d = 3, then the output will be "Three".To solve this, we will follow these steps −Define a function solve(), this will take d, if d < 0 and d > 9, then:return ("Beyond range of 0 - 9")otherwise when d is same as 0, then:return ("Zero")otherwise when d is same as ... Read More
Suppose we have a number n, we have to transform it into 0 using the following operations any number of times −Select the rightmost bit in the binary representation of n.Change the ith bit in the binary representation of n when the (i-1)th bit is set to 1 and the (i-2)th through 0th bits are set to 0.So finally we have to find the minimum number of operations required to transform n into 0.So, if the input is like n = 6, then the output will be 4 because initially 6 = "110", then convert it to "010" by second ... Read More
To store mouse event coordinates with matplotlib, we can use "button_press_event" event.−StepsSet the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Plot a line in the range of 10Bind the function *onclick* to the event *button_press_event*.Print the x and y data of the event.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams['backend'] = 'TkAgg' plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True # Function to print mouse click event coordinates def onclick(event): print([event.xdata, event.ydata]) # Create a figure and a set of subplots fig, ... Read More
Suppose, there are n number of hostel rooms numbered from 0 to n-1. The students in the hostel rooms want to transfer to another room, and they place several requests to do that. No hostel seat remains vacant, a transfer request is only taken care of if another student takes the place of the student willing to transfer. So, given the requests, we have to find out how many requests can be satisfied.So, if the input is like n = 3, requests = [[0, 2], [1, 0], [2, 1]], then the output will be 3.The student in room 0 transfers ... Read More
Suppose we have two numbers a and b, a is integer and b is a float. We shall have to take them from standard input and display the sum.So, if the input is like a = 10 b = 56.23, then the output will be Sum: 66.23To solve this, we will follow these steps −To display output into the standard output device we can use extraction operator ()ExampleLet us see the following implementation to get better understanding −#include using namespace std; int main(){ int a; float b; cout a >> b; cout
Suppose, we are given a grid where the cells contain various symbols such as 'X', 'O', '*' and '#' and the symbols have various meanings.'#' is the goal cell that we want to reach.'O' is a free cell via which we can travel to the goal cell.'*' is our position in the cell.'X' is a blocked cell, via which we cannot travel.We have to find out the number of moves required to reach the goal cell from our current position in the grid. If the goal is not reachable, we return -1. The grid is given as input to the ... Read More
Suppose we have an m x n binary matrix, we can rearrange the columns of the matrix in any order. We have to find the area of the largest submatrix within matrix where every element of the submatrix is 1 after performing some reordering task.So, if the input is like101111001then the output will be 4 because, after column swapping we are getting matrix like110111010here maximum submatrix is of square sized with four 1's.To solve this, we will follow these steps −row := number of rows of matrix, col := number of columns of matrixfor j in range 0 to col ... Read More
Suppose we have a list of numbers nums. We also have a list of queries where queries[i] contains three elements [k, p, r], for each query we shall have to find kpr_sum. The formula for kpr_sum is like below.$$\mathrm{{𝑘𝑝𝑟}\_{𝑠𝑢𝑚} =\sum_{\substack{𝑖=𝑃}}^{𝑅−1}\sum_{\substack{𝑗=𝑖+1}}^{𝑅}(𝐾 ⊕(𝐴[𝑖]⊕𝐴[𝑗]))}$$If the sum is too large, then return sum modulo 10^9+7.So, if the input is like nums = [1, 2, 3] queries = [[1, 1, 3], [2, 1, 3]], then the output will be [5, 4] because for the first element it is (1 XOR (1 XOR 2)) + (1 XOR (1 XOR 3)) + (1 XOR (2 XOR 3)) ... Read More
Suppose we have three numbers i, j and k and another number n. We shall have to find the list of all triplets (i, j, k) for which i+j+k not same as n. We shall have to solve this problem using list comprehension strategy.So, if the input is like i = 1, j = 1, z = 2 and n = 3, then the output will be [[0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 2]]To solve this, we will follow these ... Read More
Suppose we have an array nums with unique positive values, we have to find the number of tuples (a, b, c, d) such that a*b = c*d where a, b, c, and d are elements of nums, and all elements a, b, c and d are distinct.So, if the input is like nums = [2, 3, 4, 6], then the output will be 8 because we can get tuples like (2, 6, 3, 4), (2, 6, 4, 3), (6, 2, 3, 4), (6, 2, 4, 3), (3, 4, 2, 6), (4, 3, 2, 6), (3, 4, 6, 2), (4, 3, ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP