Hacker earth Binary subsequence "01" and "10" Problem Solution:
Problem Statement: Given four number x, y, a and b check if there exists a binary string having x 0's and y 1's such that the total number of subsequence equal to the sequence "01" in it is a and the total number of subsequence equal to the sequence "10" in it is b. Given: A binary string is a string made of the character '0' and '1' only. A sequence a is a subsequence of a sequence b if a can be obtained from b by deletion of several element.
Input Format
The first line contains a single integer T (1<=T<=10^5), denoting the number of test cases.
Each of the next T lines contains four integers x, y, a and b (1<=x, y<=10^5, 0<=a, b<=10^9)
Sample input:
3
3 2 4 2
3 3 6 3
3 3 4 3
Sample output
Yes
Yes
No
Code:
t=int(input())
for i in range(t):
x,y,a,b=(input()).split()
if(int(x)*int(y)==int(a)+int(b)):
print("Yes")
else:
print("No")
Screenshot of code and output:
Comments
Post a Comment