Dataset Viewer
Auto-converted to Parquet Duplicate
problem_sno
int64
problem_slug
string
title
string
problem_statement
string
sample_sno
int64
input
string
output
string
solution_sno
int64
solution_name
string
language
string
code
string
source_json_file
string
1
biggest-reuleaux-triangle-inscribed-within-a-square-which-is-inscribed-within-an-ellipse
Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
Given an ellipse with major axis length and minor axis 2a & 2b respectively which inscribes a square which in turn inscribes a reuleaux triangle. The task is to find the maximum possible area of this reuleaux triangle.
1
a = 5, b = 4
0.0722389
1
sol1
cpp
// C++ Program to find the biggest Reuleaux triangle\n// inscribed within in a square which in turn\n// is inscribed within an ellipse\n#include <bits/stdc++.h>\nusing namespace std;\n\n// Function to find the biggest reuleaux triangle\nfloat Area(float a, float b)\n{\n\n // length of the axes cannot be negative\n ...
biggest-reuleaux-triangle-inscribed-within-a-square-which-is-inscribed-within-an-ellipse.json
1
biggest-reuleaux-triangle-inscribed-within-a-square-which-is-inscribed-within-an-ellipse
Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
Given an ellipse with major axis length and minor axis 2a & 2b respectively which inscribes a square which in turn inscribes a reuleaux triangle. The task is to find the maximum possible area of this reuleaux triangle.
1
a = 5, b = 4
0.0722389
2
sol2
java
// Java Program to find the biggest Reuleaux triangle\n// inscribed within in a square which in turn\n// is inscribed within an ellipse\nimport java.io.*;\n\nclass InfobayAI \n{\n \n// Function to find the biggest reuleaux triangle\nstatic float Area(float a, float b)\n{\n\n // length of the axes cannot be negati...
biggest-reuleaux-triangle-inscribed-within-a-square-which-is-inscribed-within-an-ellipse.json
1
biggest-reuleaux-triangle-inscribed-within-a-square-which-is-inscribed-within-an-ellipse
Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
Given an ellipse with major axis length and minor axis 2a & 2b respectively which inscribes a square which in turn inscribes a reuleaux triangle. The task is to find the maximum possible area of this reuleaux triangle.
1
a = 5, b = 4
0.0722389
3
sol3
python
# Python3 Program to find the biggest Reuleaux \n# triangle inscribed within in a square\n# which in turn is inscribed within an ellipse \nimport math;\n\n# Function to find the biggest \n# reuleaux triangle \ndef Area(a, b):\n\n # length of the axes cannot \n # be negative \n if (a < 0 and b < 0): \n r...
biggest-reuleaux-triangle-inscribed-within-a-square-which-is-inscribed-within-an-ellipse.json
1
biggest-reuleaux-triangle-inscribed-within-a-square-which-is-inscribed-within-an-ellipse
Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
Given an ellipse with major axis length and minor axis 2a & 2b respectively which inscribes a square which in turn inscribes a reuleaux triangle. The task is to find the maximum possible area of this reuleaux triangle.
2
a = 7, b = 11
0.0202076
1
sol1
cpp
// C++ Program to find the biggest Reuleaux triangle\n// inscribed within in a square which in turn\n// is inscribed within an ellipse\n#include <bits/stdc++.h>\nusing namespace std;\n\n// Function to find the biggest reuleaux triangle\nfloat Area(float a, float b)\n{\n\n // length of the axes cannot be negative\n ...
biggest-reuleaux-triangle-inscribed-within-a-square-which-is-inscribed-within-an-ellipse.json
1
biggest-reuleaux-triangle-inscribed-within-a-square-which-is-inscribed-within-an-ellipse
Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
Given an ellipse with major axis length and minor axis 2a & 2b respectively which inscribes a square which in turn inscribes a reuleaux triangle. The task is to find the maximum possible area of this reuleaux triangle.
2
a = 7, b = 11
0.0202076
2
sol2
java
// Java Program to find the biggest Reuleaux triangle\n// inscribed within in a square which in turn\n// is inscribed within an ellipse\nimport java.io.*;\n\nclass InfobayAI \n{\n \n// Function to find the biggest reuleaux triangle\nstatic float Area(float a, float b)\n{\n\n // length of the axes cannot be negati...
biggest-reuleaux-triangle-inscribed-within-a-square-which-is-inscribed-within-an-ellipse.json
1
biggest-reuleaux-triangle-inscribed-within-a-square-which-is-inscribed-within-an-ellipse
Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
Given an ellipse with major axis length and minor axis 2a & 2b respectively which inscribes a square which in turn inscribes a reuleaux triangle. The task is to find the maximum possible area of this reuleaux triangle.
2
a = 7, b = 11
0.0202076
3
sol3
python
# Python3 Program to find the biggest Reuleaux \n# triangle inscribed within in a square\n# which in turn is inscribed within an ellipse \nimport math;\n\n# Function to find the biggest \n# reuleaux triangle \ndef Area(a, b):\n\n # length of the axes cannot \n # be negative \n if (a < 0 and b < 0): \n r...
biggest-reuleaux-triangle-inscribed-within-a-square-which-is-inscribed-within-an-ellipse.json
2
check-if-a-king-can-move-a-valid-move-or-not-when-n-nights-are-there-in-a-modified-chessboard
Check if a king can move a valid move or not when N nights are there in a modified chessboard
Given an infinite chessboard with the same rules as that of chess. Also given are N knights coordinates on the infinite chessboard(-10^9 <= x, y <= 10^9) and the king's coordinate, the task is to check if the King is checkmate or not.
1
a[] = { {1, 0}, {0, 2}, {2, 5}, {4, 4}, {5, 0}, {6, 2} } king -> {3, 2}
Yes The king cannot make any move as it has been check mate.
1
sol1
cpp
// C++ program for checking if a king\n// can move a valid move or not when\n// N nights are there in a modified chessboard\n#include <bits/stdc++.h>\nusing namespace std;\nbool checkCheckMate(pair<int, int> a[], int n, int kx, int ky)\n{\n\n // Pair of hash to mark the coordinates\n map<pair<int, int>, int> mpp;...
check-if-a-king-can-move-a-valid-move-or-not-when-n-nights-are-there-in-a-modified-chessboard.json
2
check-if-a-king-can-move-a-valid-move-or-not-when-n-nights-are-there-in-a-modified-chessboard
Check if a king can move a valid move or not when N nights are there in a modified chessboard
Given an infinite chessboard with the same rules as that of chess. Also given are N knights coordinates on the infinite chessboard(-10^9 <= x, y <= 10^9) and the king's coordinate, the task is to check if the King is checkmate or not.
1
a[] = { {1, 0}, {0, 2}, {2, 5}, {4, 4}, {5, 0}, {6, 2} } king -> {3, 2}
Yes The king cannot make any move as it has been check mate.
2
sol2
java
// Java program for checking if a king\n// can move a valid move or not when\n// N nights are there in a modified chessboard\nimport java.util.*;\n\nclass InfobayAI \n{\nstatic class pair\n{ \n int first, second; \n public pair(int first, int second) \n { \n this.first = first; \n this.second = s...
check-if-a-king-can-move-a-valid-move-or-not-when-n-nights-are-there-in-a-modified-chessboard.json
2
check-if-a-king-can-move-a-valid-move-or-not-when-n-nights-are-there-in-a-modified-chessboard
Check if a king can move a valid move or not when N nights are there in a modified chessboard
Given an infinite chessboard with the same rules as that of chess. Also given are N knights coordinates on the infinite chessboard(-10^9 <= x, y <= 10^9) and the king's coordinate, the task is to check if the King is checkmate or not.
1
a[] = { {1, 0}, {0, 2}, {2, 5}, {4, 4}, {5, 0}, {6, 2} } king -> {3, 2}
Yes The king cannot make any move as it has been check mate.
3
sol3
python3
# Python3 program for checking if a king \n# can move a valid move or not when \n# N nights are there in a modified chessboard \n\ndef checkCheckMate(a, n, kx, ky): \n\n # Pair of hash to mark the coordinates \n mpp = {} \n\n # iterate for Given N knights \n for i in range(0, n): \n x = a[i][0] \n ...
check-if-a-king-can-move-a-valid-move-or-not-when-n-nights-are-there-in-a-modified-chessboard.json
2
check-if-a-king-can-move-a-valid-move-or-not-when-n-nights-are-there-in-a-modified-chessboard
Check if a king can move a valid move or not when N nights are there in a modified chessboard
Given an infinite chessboard with the same rules as that of chess. Also given are N knights coordinates on the infinite chessboard(-10^9 <= x, y <= 10^9) and the king's coordinate, the task is to check if the King is checkmate or not.
2
a[] = { {1, 1} } king -> {3, 4}
No The king can make valid moves.
1
sol1
cpp
// C++ program for checking if a king\n// can move a valid move or not when\n// N nights are there in a modified chessboard\n#include <bits/stdc++.h>\nusing namespace std;\nbool checkCheckMate(pair<int, int> a[], int n, int kx, int ky)\n{\n\n // Pair of hash to mark the coordinates\n map<pair<int, int>, int> mpp;...
check-if-a-king-can-move-a-valid-move-or-not-when-n-nights-are-there-in-a-modified-chessboard.json
2
check-if-a-king-can-move-a-valid-move-or-not-when-n-nights-are-there-in-a-modified-chessboard
Check if a king can move a valid move or not when N nights are there in a modified chessboard
Given an infinite chessboard with the same rules as that of chess. Also given are N knights coordinates on the infinite chessboard(-10^9 <= x, y <= 10^9) and the king's coordinate, the task is to check if the King is checkmate or not.
2
a[] = { {1, 1} } king -> {3, 4}
No The king can make valid moves.
2
sol2
java
// Java program for checking if a king\n// can move a valid move or not when\n// N nights are there in a modified chessboard\nimport java.util.*;\n\nclass InfobayAI \n{\nstatic class pair\n{ \n int first, second; \n public pair(int first, int second) \n { \n this.first = first; \n this.second = s...
check-if-a-king-can-move-a-valid-move-or-not-when-n-nights-are-there-in-a-modified-chessboard.json
2
check-if-a-king-can-move-a-valid-move-or-not-when-n-nights-are-there-in-a-modified-chessboard
Check if a king can move a valid move or not when N nights are there in a modified chessboard
Given an infinite chessboard with the same rules as that of chess. Also given are N knights coordinates on the infinite chessboard(-10^9 <= x, y <= 10^9) and the king's coordinate, the task is to check if the King is checkmate or not.
2
a[] = { {1, 1} } king -> {3, 4}
No The king can make valid moves.
3
sol3
python3
# Python3 program for checking if a king \n# can move a valid move or not when \n# N nights are there in a modified chessboard \n\ndef checkCheckMate(a, n, kx, ky): \n\n # Pair of hash to mark the coordinates \n mpp = {} \n\n # iterate for Given N knights \n for i in range(0, n): \n x = a[i][0] \n ...
check-if-a-king-can-move-a-valid-move-or-not-when-n-nights-are-there-in-a-modified-chessboard.json
3
check-if-array-has-at-least-m-non-overlapping-subarray-with-gcd-g
Check if Array has at least M non-overlapping Subarray with gcd G
Given an array A[] and M, the task is to check whether there exist M non-overlapping subarrays(non-empty) of A for which the average of the GCD of those subarrays equals G where G denotes the gcd of all the numbers in the array A.
1
A[] = {1, 2, 3, 4, 5}, M = 3
Yes ?Explanation: Here, G = gcd(1, 2, 3, 4, 5) = 1. We can choose 3 non overlapping subarrays {[1], [2, 3], [4, 5]} where gcd(1) = 1, gcd(2, 3) = 1, and gcd(4, 5) = 1. Thus, the average = (1 + 1 + 1)/3 = 1. Hence, we can have 3 such subarrays.
1
sol1
cpp
// C++ code to implement the approach\n#include <bits/stdc++.h>\nusing namespace std;\n\n// Function to find gcd of two numbers\nint gcd(int a, int b)\n{\n if (b == 0)\n {\n return a;\n }\n return gcd(b, a % b);\n}\n\n// Function to find check whether\n// non-overlapping subarray exists\nstring find(...
check-if-array-has-at-least-m-non-overlapping-subarray-with-gcd-g.json
3
check-if-array-has-at-least-m-non-overlapping-subarray-with-gcd-g
Check if Array has at least M non-overlapping Subarray with gcd G
Given an array A[] and M, the task is to check whether there exist M non-overlapping subarrays(non-empty) of A for which the average of the GCD of those subarrays equals G where G denotes the gcd of all the numbers in the array A.
1
A[] = {1, 2, 3, 4, 5}, M = 3
Yes ?Explanation: Here, G = gcd(1, 2, 3, 4, 5) = 1. We can choose 3 non overlapping subarrays {[1], [2, 3], [4, 5]} where gcd(1) = 1, gcd(2, 3) = 1, and gcd(4, 5) = 1. Thus, the average = (1 + 1 + 1)/3 = 1. Hence, we can have 3 such subarrays.
2
sol2
java
// Java code to implement the approach\n\nimport java.io.*;\nimport java.util.*;\n\npublic class InfobayAI {\n\n // Function to find gcd of two numbers\n public static int gcd(int a, int b)\n {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n // Function to ...
check-if-array-has-at-least-m-non-overlapping-subarray-with-gcd-g.json
3
check-if-array-has-at-least-m-non-overlapping-subarray-with-gcd-g
Check if Array has at least M non-overlapping Subarray with gcd G
Given an array A[] and M, the task is to check whether there exist M non-overlapping subarrays(non-empty) of A for which the average of the GCD of those subarrays equals G where G denotes the gcd of all the numbers in the array A.
1
A[] = {1, 2, 3, 4, 5}, M = 3
Yes ?Explanation: Here, G = gcd(1, 2, 3, 4, 5) = 1. We can choose 3 non overlapping subarrays {[1], [2, 3], [4, 5]} where gcd(1) = 1, gcd(2, 3) = 1, and gcd(4, 5) = 1. Thus, the average = (1 + 1 + 1)/3 = 1. Hence, we can have 3 such subarrays.
3
sol3
python
# Python code to implement the approach\n\n# Function to find gcd of two numbers\ndef gcd(a, b):\n if (b == 0):\n return a\n return gcd(b, a % b)\n\n# Function to find check whether\n# non-overlapping subarray exists\ndef find(arr, n, m):\n G = 0\n g = 0\n count = 0\n for i in range(n):\n ...
check-if-array-has-at-least-m-non-overlapping-subarray-with-gcd-g.json
3
check-if-array-has-at-least-m-non-overlapping-subarray-with-gcd-g
Check if Array has at least M non-overlapping Subarray with gcd G
Given an array A[] and M, the task is to check whether there exist M non-overlapping subarrays(non-empty) of A for which the average of the GCD of those subarrays equals G where G denotes the gcd of all the numbers in the array A.
2
A[] = {6, 12, 18, 24}
No
1
sol1
cpp
// C++ code to implement the approach\n#include <bits/stdc++.h>\nusing namespace std;\n\n// Function to find gcd of two numbers\nint gcd(int a, int b)\n{\n if (b == 0)\n {\n return a;\n }\n return gcd(b, a % b);\n}\n\n// Function to find check whether\n// non-overlapping subarray exists\nstring find(...
check-if-array-has-at-least-m-non-overlapping-subarray-with-gcd-g.json
3
check-if-array-has-at-least-m-non-overlapping-subarray-with-gcd-g
Check if Array has at least M non-overlapping Subarray with gcd G
Given an array A[] and M, the task is to check whether there exist M non-overlapping subarrays(non-empty) of A for which the average of the GCD of those subarrays equals G where G denotes the gcd of all the numbers in the array A.
2
A[] = {6, 12, 18, 24}
No
2
sol2
java
// Java code to implement the approach\n\nimport java.io.*;\nimport java.util.*;\n\npublic class InfobayAI {\n\n // Function to find gcd of two numbers\n public static int gcd(int a, int b)\n {\n if (b == 0) {\n return a;\n }\n return gcd(b, a % b);\n }\n\n // Function to ...
check-if-array-has-at-least-m-non-overlapping-subarray-with-gcd-g.json
3
check-if-array-has-at-least-m-non-overlapping-subarray-with-gcd-g
Check if Array has at least M non-overlapping Subarray with gcd G
Given an array A[] and M, the task is to check whether there exist M non-overlapping subarrays(non-empty) of A for which the average of the GCD of those subarrays equals G where G denotes the gcd of all the numbers in the array A.
2
A[] = {6, 12, 18, 24}
No
3
sol3
python
# Python code to implement the approach\n\n# Function to find gcd of two numbers\ndef gcd(a, b):\n if (b == 0):\n return a\n return gcd(b, a % b)\n\n# Function to find check whether\n# non-overlapping subarray exists\ndef find(arr, n, m):\n G = 0\n g = 0\n count = 0\n for i in range(n):\n ...
check-if-array-has-at-least-m-non-overlapping-subarray-with-gcd-g.json
4
count-arrays-having-at-least-k-elements-exceeding-xor-of-all-given-array-elements-by-x-given-operations
Count arrays having at least K elements exceeding XOR of all given array elements by X given operations
Given an array arr[] of size N, the task is to count the number of arrays having at least K elements greater than the XOR of all array elements, generated by performing the following operations X times. Select either first or last element from the given array. Either increment the selected element by 1 or delete the se...
1
arr[] = {10, 2, 10, 5}, X = 3, K = 3
1 Explanation: XOR of the given array = 7. The only possible array satisfying the condition is {10, 2, 10, 8}, obtained by incrementing the last array element thrice.
1
sol1
cpp
// C++ program for the above approach\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n// Stores the final answer\nint ans = 0;\n\n// Utility function to count arrays\n// having at least K elements exceeding\n// XOR of all given array elements\nvoid countArraysUtil(vector<int>& arr,\n int X, int...
count-arrays-having-at-least-k-elements-exceeding-xor-of-all-given-array-elements-by-x-given-operations.json
4
count-arrays-having-at-least-k-elements-exceeding-xor-of-all-given-array-elements-by-x-given-operations
Count arrays having at least K elements exceeding XOR of all given array elements by X given operations
Given an array arr[] of size N, the task is to count the number of arrays having at least K elements greater than the XOR of all array elements, generated by performing the following operations X times. Select either first or last element from the given array. Either increment the selected element by 1 or delete the se...
1
arr[] = {10, 2, 10, 5}, X = 3, K = 3
1 Explanation: XOR of the given array = 7. The only possible array satisfying the condition is {10, 2, 10, 8}, obtained by incrementing the last array element thrice.
2
sol2
java
// Java program for the above approach\nimport java.util.ArrayList;\nclass InfobayAI{\n\n// Stores the final answer\nstatic int ans = 0;\n\n// Utility function to count arrays\n// having at least K elements exceeding\n// XOR of all given array elements\npublic static void countArraysUtil(ArrayList<Integer> arr,\n ...
count-arrays-having-at-least-k-elements-exceeding-xor-of-all-given-array-elements-by-x-given-operations.json
4
count-arrays-having-at-least-k-elements-exceeding-xor-of-all-given-array-elements-by-x-given-operations
Count arrays having at least K elements exceeding XOR of all given array elements by X given operations
Given an array arr[] of size N, the task is to count the number of arrays having at least K elements greater than the XOR of all array elements, generated by performing the following operations X times. Select either first or last element from the given array. Either increment the selected element by 1 or delete the se...
1
arr[] = {10, 2, 10, 5}, X = 3, K = 3
1 Explanation: XOR of the given array = 7. The only possible array satisfying the condition is {10, 2, 10, 8}, obtained by incrementing the last array element thrice.
3
sol3
python
# Python program for the above approach\n\n# Stores the final answer\nans = 0\n\n# Utility function to count arrays\n# having at least K elements exceeding\n# XOR of all given array elements\ndef countArraysUtil( arr, X, K, xorVal):\n global ans\n \n # If no operations are left\n if (X == 0):\n \n ...
count-arrays-having-at-least-k-elements-exceeding-xor-of-all-given-array-elements-by-x-given-operations.json
4
count-arrays-having-at-least-k-elements-exceeding-xor-of-all-given-array-elements-by-x-given-operations
Count arrays having at least K elements exceeding XOR of all given array elements by X given operations
Given an array arr[] of size N, the task is to count the number of arrays having at least K elements greater than the XOR of all array elements, generated by performing the following operations X times. Select either first or last element from the given array. Either increment the selected element by 1 or delete the se...
2
arr[] = {3, 3, 4}, X = 3, K = 2
3
1
sol1
cpp
// C++ program for the above approach\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n// Stores the final answer\nint ans = 0;\n\n// Utility function to count arrays\n// having at least K elements exceeding\n// XOR of all given array elements\nvoid countArraysUtil(vector<int>& arr,\n int X, int...
count-arrays-having-at-least-k-elements-exceeding-xor-of-all-given-array-elements-by-x-given-operations.json
4
count-arrays-having-at-least-k-elements-exceeding-xor-of-all-given-array-elements-by-x-given-operations
Count arrays having at least K elements exceeding XOR of all given array elements by X given operations
Given an array arr[] of size N, the task is to count the number of arrays having at least K elements greater than the XOR of all array elements, generated by performing the following operations X times. Select either first or last element from the given array. Either increment the selected element by 1 or delete the se...
2
arr[] = {3, 3, 4}, X = 3, K = 2
3
2
sol2
java
// Java program for the above approach\nimport java.util.ArrayList;\nclass InfobayAI{\n\n// Stores the final answer\nstatic int ans = 0;\n\n// Utility function to count arrays\n// having at least K elements exceeding\n// XOR of all given array elements\npublic static void countArraysUtil(ArrayList<Integer> arr,\n ...
count-arrays-having-at-least-k-elements-exceeding-xor-of-all-given-array-elements-by-x-given-operations.json
4
count-arrays-having-at-least-k-elements-exceeding-xor-of-all-given-array-elements-by-x-given-operations
Count arrays having at least K elements exceeding XOR of all given array elements by X given operations
Given an array arr[] of size N, the task is to count the number of arrays having at least K elements greater than the XOR of all array elements, generated by performing the following operations X times. Select either first or last element from the given array. Either increment the selected element by 1 or delete the se...
2
arr[] = {3, 3, 4}, X = 3, K = 2
3
3
sol3
python
# Python program for the above approach\n\n# Stores the final answer\nans = 0\n\n# Utility function to count arrays\n# having at least K elements exceeding\n# XOR of all given array elements\ndef countArraysUtil( arr, X, K, xorVal):\n global ans\n \n # If no operations are left\n if (X == 0):\n \n ...
count-arrays-having-at-least-k-elements-exceeding-xor-of-all-given-array-elements-by-x-given-operations.json
5
count-of-distinct-coprime-pairs-product-of-which-divides-all-elements-in-index-l-r-for-q-queries
Count of distinct coprime pairs product of which divides all elements in index [L, R] for Q queries
Given an array arr[] of N integers and Q queries of the form (l, r). The task is to find the number of distinct pairs of coprime integers for each query such that all integers in index range [l, r] are divisible by the product of the coprime integers.
1
arr[] = {1, 2, 2, 4, 5}, queries[] = {{2, 3}, {2, 4}, {3, 4}, {4, 4}, {4, 5}}
3 3 3 5 1 Explanation: For 1st query [2, 3], the subarray is {2, 2}. The pairs of coprimes that divide all the integers in the subarray are {1, 1}, {1, 2} and {2, 1}. For 2nd query [2, 4], the subarray is {2, 2, 4}. The pairs of coprimes that divide all the integers are {1, 1}, {1, 2} and {2, 1}. Similarly, proceed for...
1
sol1
cpp
// C++ program for the above approach\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define MAXN 200001\nint table[1001][1001];\n\n// Function to build sparse table\nvoid buildSparseTable(vector<int> arr, int n)\n{\n // GCD of single element is\n // the element itself\n for (int i = 0; i < n; i++)\n ...
count-of-distinct-coprime-pairs-product-of-which-divides-all-elements-in-index-l-r-for-q-queries.json
5
count-of-distinct-coprime-pairs-product-of-which-divides-all-elements-in-index-l-r-for-q-queries
Count of distinct coprime pairs product of which divides all elements in index [L, R] for Q queries
Given an array arr[] of N integers and Q queries of the form (l, r). The task is to find the number of distinct pairs of coprime integers for each query such that all integers in index range [l, r] are divisible by the product of the coprime integers.
1
arr[] = {1, 2, 2, 4, 5}, queries[] = {{2, 3}, {2, 4}, {3, 4}, {4, 4}, {4, 5}}
3 3 3 5 1 Explanation: For 1st query [2, 3], the subarray is {2, 2}. The pairs of coprimes that divide all the integers in the subarray are {1, 1}, {1, 2} and {2, 1}. For 2nd query [2, 4], the subarray is {2, 2, 4}. The pairs of coprimes that divide all the integers are {1, 1}, {1, 2} and {2, 1}. Similarly, proceed for...
2
sol2
java
// Java program for the above approach\nimport java.util.*;\n\nclass InfobayAI{\n\n static final int MAXN = 200001;\n static int [][]table = new int[1001][1001];\n\n // Function to build sparse table\n static void buildSparseTable(int[] arr, int n)\n {\n\n // GCD of single element is\n // the element itself\...
count-of-distinct-coprime-pairs-product-of-which-divides-all-elements-in-index-l-r-for-q-queries.json
5
count-of-distinct-coprime-pairs-product-of-which-divides-all-elements-in-index-l-r-for-q-queries
Count of distinct coprime pairs product of which divides all elements in index [L, R] for Q queries
Given an array arr[] of N integers and Q queries of the form (l, r). The task is to find the number of distinct pairs of coprime integers for each query such that all integers in index range [l, r] are divisible by the product of the coprime integers.
1
arr[] = {1, 2, 2, 4, 5}, queries[] = {{2, 3}, {2, 4}, {3, 4}, {4, 4}, {4, 5}}
3 3 3 5 1 Explanation: For 1st query [2, 3], the subarray is {2, 2}. The pairs of coprimes that divide all the integers in the subarray are {1, 1}, {1, 2} and {2, 1}. For 2nd query [2, 4], the subarray is {2, 2, 4}. The pairs of coprimes that divide all the integers are {1, 1}, {1, 2} and {2, 1}. Similarly, proceed for...
3
sol3
python
# python program for the above approach\nimport math\nMAXN = 200001\n\n# creating 2-D table of size 1001*1001\ntable = []\n\nfor i in range(0, 1001):\n table.append([])\n for j in range(0, 1001):\n table[i].append([])\n\n# Function to build sparse table\ndef buildSparseTable(arr, n):\n\n # GCD of si...
count-of-distinct-coprime-pairs-product-of-which-divides-all-elements-in-index-l-r-for-q-queries.json
5
count-of-distinct-coprime-pairs-product-of-which-divides-all-elements-in-index-l-r-for-q-queries
Count of distinct coprime pairs product of which divides all elements in index [L, R] for Q queries
Given an array arr[] of N integers and Q queries of the form (l, r). The task is to find the number of distinct pairs of coprime integers for each query such that all integers in index range [l, r] are divisible by the product of the coprime integers.
2
arr[] = {20, 10, 15}, queries[] = {{2, 3}, {1, 3}, {1, 2}}
3 3 9
1
sol1
cpp
// C++ program for the above approach\n#include <bits/stdc++.h>\nusing namespace std;\n\n#define MAXN 200001\nint table[1001][1001];\n\n// Function to build sparse table\nvoid buildSparseTable(vector<int> arr, int n)\n{\n // GCD of single element is\n // the element itself\n for (int i = 0; i < n; i++)\n ...
count-of-distinct-coprime-pairs-product-of-which-divides-all-elements-in-index-l-r-for-q-queries.json
5
count-of-distinct-coprime-pairs-product-of-which-divides-all-elements-in-index-l-r-for-q-queries
Count of distinct coprime pairs product of which divides all elements in index [L, R] for Q queries
Given an array arr[] of N integers and Q queries of the form (l, r). The task is to find the number of distinct pairs of coprime integers for each query such that all integers in index range [l, r] are divisible by the product of the coprime integers.
2
arr[] = {20, 10, 15}, queries[] = {{2, 3}, {1, 3}, {1, 2}}
3 3 9
2
sol2
java
// Java program for the above approach\nimport java.util.*;\n\nclass InfobayAI{\n\n static final int MAXN = 200001;\n static int [][]table = new int[1001][1001];\n\n // Function to build sparse table\n static void buildSparseTable(int[] arr, int n)\n {\n\n // GCD of single element is\n // the element itself\...
count-of-distinct-coprime-pairs-product-of-which-divides-all-elements-in-index-l-r-for-q-queries.json
5
count-of-distinct-coprime-pairs-product-of-which-divides-all-elements-in-index-l-r-for-q-queries
Count of distinct coprime pairs product of which divides all elements in index [L, R] for Q queries
Given an array arr[] of N integers and Q queries of the form (l, r). The task is to find the number of distinct pairs of coprime integers for each query such that all integers in index range [l, r] are divisible by the product of the coprime integers.
2
arr[] = {20, 10, 15}, queries[] = {{2, 3}, {1, 3}, {1, 2}}
3 3 9
3
sol3
python
# python program for the above approach\nimport math\nMAXN = 200001\n\n# creating 2-D table of size 1001*1001\ntable = []\n\nfor i in range(0, 1001):\n table.append([])\n for j in range(0, 1001):\n table[i].append([])\n\n# Function to build sparse table\ndef buildSparseTable(arr, n):\n\n # GCD of si...
count-of-distinct-coprime-pairs-product-of-which-divides-all-elements-in-index-l-r-for-q-queries.json
6
count-the-number-of-subsequences-of-length-k-having-equal-lcm-and-hcf
Count the number of subsequences of length k having equal LCM and HCF
Given an array Arr and an integer K . The task is to find the number of subsequences of size K such that the LCM and HCF of the sequence is same.
1
Arr = {1, 2, 2, 3, 3}, K = 2
2 Subsequences are - {2, 2} and {3, 3}
1
sol1
cpp14
// C++ implementation\n#include <bits/stdc++.h>\nusing namespace std;\n\n// Returns factorial of n\nlong long fact(int n)\n{\n long long res = 1;\n for (int i = 2; i <= n; i++)\n res = res * i;\n return res;\n}\n\n// Returns nCr for the\n// given values of r and n\nlong long nCr(int n, int r)\n{\n re...
count-the-number-of-subsequences-of-length-k-having-equal-lcm-and-hcf.json
6
count-the-number-of-subsequences-of-length-k-having-equal-lcm-and-hcf
Count the number of subsequences of length k having equal LCM and HCF
Given an array Arr and an integer K . The task is to find the number of subsequences of size K such that the LCM and HCF of the sequence is same.
1
Arr = {1, 2, 2, 3, 3}, K = 2
2 Subsequences are - {2, 2} and {3, 3}
2
sol2
java
// Java implementation for above approach\nimport java.util.*;\n \nclass InfobayAI\n{\n\n// Returns factorial of n\nstatic long fact(int n)\n{\n long res = 1;\n for (int i = 2; i <= n; i++)\n res = res * i;\n return res;\n}\n\n// Returns nCr for the\n// given values of r and n\nstatic long nCr(int n,...
count-the-number-of-subsequences-of-length-k-having-equal-lcm-and-hcf.json
6
count-the-number-of-subsequences-of-length-k-having-equal-lcm-and-hcf
Count the number of subsequences of length k having equal LCM and HCF
Given an array Arr and an integer K . The task is to find the number of subsequences of size K such that the LCM and HCF of the sequence is same.
1
Arr = {1, 2, 2, 3, 3}, K = 2
2 Subsequences are - {2, 2} and {3, 3}
3
sol3
python3
# Python3 implementation of above approach\n\n# Returns factorial of n\ndef fact(n):\n res = 1\n for i in range(2, n + 1):\n res = res * i\n return res\n\n# Returns nCr for the\n# given values of r and n\ndef nCr(n, r):\n return fact(n) // (fact(r) * fact(n - r))\n\ndef number_of_subsequences(arr, k,...
count-the-number-of-subsequences-of-length-k-having-equal-lcm-and-hcf.json
6
count-the-number-of-subsequences-of-length-k-having-equal-lcm-and-hcf
Count the number of subsequences of length k having equal LCM and HCF
Given an array Arr and an integer K . The task is to find the number of subsequences of size K such that the LCM and HCF of the sequence is same.
2
Arr = {1, 1, 1, 1, 2, 2}, K = 3
4
1
sol1
cpp14
// C++ implementation\n#include <bits/stdc++.h>\nusing namespace std;\n\n// Returns factorial of n\nlong long fact(int n)\n{\n long long res = 1;\n for (int i = 2; i <= n; i++)\n res = res * i;\n return res;\n}\n\n// Returns nCr for the\n// given values of r and n\nlong long nCr(int n, int r)\n{\n re...
count-the-number-of-subsequences-of-length-k-having-equal-lcm-and-hcf.json
6
count-the-number-of-subsequences-of-length-k-having-equal-lcm-and-hcf
Count the number of subsequences of length k having equal LCM and HCF
Given an array Arr and an integer K . The task is to find the number of subsequences of size K such that the LCM and HCF of the sequence is same.
2
Arr = {1, 1, 1, 1, 2, 2}, K = 3
4
2
sol2
java
// Java implementation for above approach\nimport java.util.*;\n \nclass InfobayAI\n{\n\n// Returns factorial of n\nstatic long fact(int n)\n{\n long res = 1;\n for (int i = 2; i <= n; i++)\n res = res * i;\n return res;\n}\n\n// Returns nCr for the\n// given values of r and n\nstatic long nCr(int n,...
count-the-number-of-subsequences-of-length-k-having-equal-lcm-and-hcf.json
6
count-the-number-of-subsequences-of-length-k-having-equal-lcm-and-hcf
Count the number of subsequences of length k having equal LCM and HCF
Given an array Arr and an integer K . The task is to find the number of subsequences of size K such that the LCM and HCF of the sequence is same.
2
Arr = {1, 1, 1, 1, 2, 2}, K = 3
4
3
sol3
python3
# Python3 implementation of above approach\n\n# Returns factorial of n\ndef fact(n):\n res = 1\n for i in range(2, n + 1):\n res = res * i\n return res\n\n# Returns nCr for the\n# given values of r and n\ndef nCr(n, r):\n return fact(n) // (fact(r) * fact(n - r))\n\ndef number_of_subsequences(arr, k,...
count-the-number-of-subsequences-of-length-k-having-equal-lcm-and-hcf.json
7
find-product-of-all-elements-at-indexes-which-are-factors-of-m-for-all-possible-sorted-subsequences-of-length-m
Find product of all elements at indexes which are factors of M for all possible sorted subsequences of length M
Given an array arr[] of N distinct integers and a positive integer M, the task is to find the product of all the elements at the indexes which are the factors of M for all the possible sorted subsequences of length M from the given array arr[]. Note: The product may be very large, take modulo to 109 + 7.
1
arr[] = {4, 7, 5, 9, 3}, M = 4
808556639 Explanation: There are five possible sets. They are: {4, 7, 5, 9}. In the sorted order, this set becomes {4, 5, 7, 9}. In this set, index 1, 2 and 4 divides M completely. Therefore, arr[1] * arr[2] * arr[4] = 4 * 5 * 9 = 180. Similarly, the remaining four sets along with their products are: {4, 7, 9, 3} -> 10...
1
sol1
cpp
// C++ program to find the product of\n// all the combinations of M elements\n// from an array whose index in the\n// sorted order divides M completely\n\n#include <bits/stdc++.h>\nusing namespace std;\n\ntypedef long long int lli;\nconst int m = 4;\n\n// Iterative Function to calculate\n// (x^y)%p in O(log y)\nlong lo...
find-product-of-all-elements-at-indexes-which-are-factors-of-m-for-all-possible-sorted-subsequences-of-length-m.json
7
find-product-of-all-elements-at-indexes-which-are-factors-of-m-for-all-possible-sorted-subsequences-of-length-m
Find product of all elements at indexes which are factors of M for all possible sorted subsequences of length M
Given an array arr[] of N distinct integers and a positive integer M, the task is to find the product of all the elements at the indexes which are the factors of M for all the possible sorted subsequences of length M from the given array arr[]. Note: The product may be very large, take modulo to 109 + 7.
1
arr[] = {4, 7, 5, 9, 3}, M = 4
808556639 Explanation: There are five possible sets. They are: {4, 7, 5, 9}. In the sorted order, this set becomes {4, 5, 7, 9}. In this set, index 1, 2 and 4 divides M completely. Therefore, arr[1] * arr[2] * arr[4] = 4 * 5 * 9 = 180. Similarly, the remaining four sets along with their products are: {4, 7, 9, 3} -> 10...
2
sol2
java
// Java program to find the product of\n// all the combinations of M elements\n// from an array whose index in the\n// sorted order divides M completely\nimport java.util.*;\n\nclass InfobayAI{\n\nstatic int m = 4;\n\n// Iterative Function to calculate\n// (x^y)%p in O(log y)\nstatic long power(long x, long y, long p)\...
find-product-of-all-elements-at-indexes-which-are-factors-of-m-for-all-possible-sorted-subsequences-of-length-m.json
7
find-product-of-all-elements-at-indexes-which-are-factors-of-m-for-all-possible-sorted-subsequences-of-length-m
Find product of all elements at indexes which are factors of M for all possible sorted subsequences of length M
Given an array arr[] of N distinct integers and a positive integer M, the task is to find the product of all the elements at the indexes which are the factors of M for all the possible sorted subsequences of length M from the given array arr[]. Note: The product may be very large, take modulo to 109 + 7.
1
arr[] = {4, 7, 5, 9, 3}, M = 4
808556639 Explanation: There are five possible sets. They are: {4, 7, 5, 9}. In the sorted order, this set becomes {4, 5, 7, 9}. In this set, index 1, 2 and 4 divides M completely. Therefore, arr[1] * arr[2] * arr[4] = 4 * 5 * 9 = 180. Similarly, the remaining four sets along with their products are: {4, 7, 9, 3} -> 10...
3
sol3
python
# Python3 program to find the product of\n# all the combinations of M elements\n# from an array whose index in the\n# sorted order divides M completely\nm = 4\n\n# Iterative Function to calculate\n# (x^y)%p in O(log y)\ndef power(x, y, p):\n\n res = 1\n x = x % p\n\n while (y > 0):\n\n # If y is odd, mu...
find-product-of-all-elements-at-indexes-which-are-factors-of-m-for-all-possible-sorted-subsequences-of-length-m.json
7
find-product-of-all-elements-at-indexes-which-are-factors-of-m-for-all-possible-sorted-subsequences-of-length-m
Find product of all elements at indexes which are factors of M for all possible sorted subsequences of length M
Given an array arr[] of N distinct integers and a positive integer M, the task is to find the product of all the elements at the indexes which are the factors of M for all the possible sorted subsequences of length M from the given array arr[]. Note: The product may be very large, take modulo to 109 + 7.
2
arr[] = {7, 8, 9}, M = 2
254016
1
sol1
cpp
// C++ program to find the product of\n// all the combinations of M elements\n// from an array whose index in the\n// sorted order divides M completely\n\n#include <bits/stdc++.h>\nusing namespace std;\n\ntypedef long long int lli;\nconst int m = 4;\n\n// Iterative Function to calculate\n// (x^y)%p in O(log y)\nlong lo...
find-product-of-all-elements-at-indexes-which-are-factors-of-m-for-all-possible-sorted-subsequences-of-length-m.json
7
find-product-of-all-elements-at-indexes-which-are-factors-of-m-for-all-possible-sorted-subsequences-of-length-m
Find product of all elements at indexes which are factors of M for all possible sorted subsequences of length M
Given an array arr[] of N distinct integers and a positive integer M, the task is to find the product of all the elements at the indexes which are the factors of M for all the possible sorted subsequences of length M from the given array arr[]. Note: The product may be very large, take modulo to 109 + 7.
2
arr[] = {7, 8, 9}, M = 2
254016
2
sol2
java
// Java program to find the product of\n// all the combinations of M elements\n// from an array whose index in the\n// sorted order divides M completely\nimport java.util.*;\n\nclass InfobayAI{\n\nstatic int m = 4;\n\n// Iterative Function to calculate\n// (x^y)%p in O(log y)\nstatic long power(long x, long y, long p)\...
find-product-of-all-elements-at-indexes-which-are-factors-of-m-for-all-possible-sorted-subsequences-of-length-m.json
7
find-product-of-all-elements-at-indexes-which-are-factors-of-m-for-all-possible-sorted-subsequences-of-length-m
Find product of all elements at indexes which are factors of M for all possible sorted subsequences of length M
Given an array arr[] of N distinct integers and a positive integer M, the task is to find the product of all the elements at the indexes which are the factors of M for all the possible sorted subsequences of length M from the given array arr[]. Note: The product may be very large, take modulo to 109 + 7.
2
arr[] = {7, 8, 9}, M = 2
254016
3
sol3
python
# Python3 program to find the product of\n# all the combinations of M elements\n# from an array whose index in the\n# sorted order divides M completely\nm = 4\n\n# Iterative Function to calculate\n# (x^y)%p in O(log y)\ndef power(x, y, p):\n\n res = 1\n x = x % p\n\n while (y > 0):\n\n # If y is odd, mu...
find-product-of-all-elements-at-indexes-which-are-factors-of-m-for-all-possible-sorted-subsequences-of-length-m.json
8
hamiltonian-cycle
Hamiltonian Cycle
A Hamiltonian Cycle or Circuit in a graph G is a cycle that visits each vertex of G exactly once and returns to the starting vertex. If a graph has a Hamiltonian cycle, it's a Hamiltonian graph; otherwise, it's non-Hamiltonian. Finding a Hamiltonian cycle is an NP-complete problem, meaning there's no known efficient so...
1
N=5, adjMat[][] = [[0, 1, 0, 1, 0], [1, 0, 1, 1, 1], [0, 1, 0, 0, 1], [1, 1, 0, 0, 1], [0, 1, 1, 1, 0]]
[0, 1, 2, 4, 3, 0]
1
sol1
cpp
#include <iostream>\n#include <vector>\n\nusing namespace std;\n\n// Check if it's valid to place vertex at current position\nbool isSafe(int vertex, vector<vector<int>> &adjMat, \n vector<int> &path, int pos) {\n \n // The vertex must be adjacent to the previous vertex\n if (!adjMat[path[pos - 1]][...
hamiltonian-cycle.json
8
hamiltonian-cycle
Hamiltonian Cycle
A Hamiltonian Cycle or Circuit in a graph G is a cycle that visits each vertex of G exactly once and returns to the starting vertex. If a graph has a Hamiltonian cycle, it's a Hamiltonian graph; otherwise, it's non-Hamiltonian. Finding a Hamiltonian cycle is an NP-complete problem, meaning there's no known efficient so...
1
N=5, adjMat[][] = [[0, 1, 0, 1, 0], [1, 0, 1, 1, 1], [0, 1, 0, 0, 1], [1, 1, 0, 0, 1], [0, 1, 1, 1, 0]]
[0, 1, 2, 4, 3, 0]
2
sol2
java
import java.util.ArrayList;\nimport java.util.List;\n\npublic class InfobayAI {\n \n // Check if it's valid to place vertex at current position\n private static boolean isSafe(int vertex, int[][] adjMat, \n List<Integer> path, int pos) {\n \n // The vertex must ...
hamiltonian-cycle.json
8
hamiltonian-cycle
Hamiltonian Cycle
A Hamiltonian Cycle or Circuit in a graph G is a cycle that visits each vertex of G exactly once and returns to the starting vertex. If a graph has a Hamiltonian cycle, it's a Hamiltonian graph; otherwise, it's non-Hamiltonian. Finding a Hamiltonian cycle is an NP-complete problem, meaning there's no known efficient so...
1
N=5, adjMat[][] = [[0, 1, 0, 1, 0], [1, 0, 1, 1, 1], [0, 1, 0, 0, 1], [1, 1, 0, 0, 1], [0, 1, 1, 1, 0]]
[0, 1, 2, 4, 3, 0]
3
sol3
python
# Check if it's valid to place vertex at current position\ndef isSafe(vertex, adjMat, path, pos):\n\n # The vertex must be adjacent to the previous vertex\n if adjMat[path[pos - 1]][vertex] == 0:\n return False\n\n # The vertex must not already be in the path\n for i in range(pos):\n if path[i...
hamiltonian-cycle.json
8
hamiltonian-cycle
Hamiltonian Cycle
A Hamiltonian Cycle or Circuit in a graph G is a cycle that visits each vertex of G exactly once and returns to the starting vertex. If a graph has a Hamiltonian cycle, it's a Hamiltonian graph; otherwise, it's non-Hamiltonian. Finding a Hamiltonian cycle is an NP-complete problem, meaning there's no known efficient so...
2
N=5, adjMat[][] = [[0, 1, 0, 1, 0], [1, 0, 1, 1, 1], [0, 1, 0, 0, 1], [1, 1, 0, 0, 0], [0, 1, 1, 0, 0]]
"Solution Does Not Exists"
1
sol1
cpp
#include <iostream>\n#include <vector>\n\nusing namespace std;\n\n// Check if it's valid to place vertex at current position\nbool isSafe(int vertex, vector<vector<int>> &adjMat, \n vector<int> &path, int pos) {\n \n // The vertex must be adjacent to the previous vertex\n if (!adjMat[path[pos - 1]][...
hamiltonian-cycle.json
8
hamiltonian-cycle
Hamiltonian Cycle
A Hamiltonian Cycle or Circuit in a graph G is a cycle that visits each vertex of G exactly once and returns to the starting vertex. If a graph has a Hamiltonian cycle, it's a Hamiltonian graph; otherwise, it's non-Hamiltonian. Finding a Hamiltonian cycle is an NP-complete problem, meaning there's no known efficient so...
2
N=5, adjMat[][] = [[0, 1, 0, 1, 0], [1, 0, 1, 1, 1], [0, 1, 0, 0, 1], [1, 1, 0, 0, 0], [0, 1, 1, 0, 0]]
"Solution Does Not Exists"
2
sol2
java
import java.util.ArrayList;\nimport java.util.List;\n\npublic class InfobayAI {\n \n // Check if it's valid to place vertex at current position\n private static boolean isSafe(int vertex, int[][] adjMat, \n List<Integer> path, int pos) {\n \n // The vertex must ...
hamiltonian-cycle.json
8
hamiltonian-cycle
Hamiltonian Cycle
A Hamiltonian Cycle or Circuit in a graph G is a cycle that visits each vertex of G exactly once and returns to the starting vertex. If a graph has a Hamiltonian cycle, it's a Hamiltonian graph; otherwise, it's non-Hamiltonian. Finding a Hamiltonian cycle is an NP-complete problem, meaning there's no known efficient so...
2
N=5, adjMat[][] = [[0, 1, 0, 1, 0], [1, 0, 1, 1, 1], [0, 1, 0, 0, 1], [1, 1, 0, 0, 0], [0, 1, 1, 0, 0]]
"Solution Does Not Exists"
3
sol3
python
# Check if it's valid to place vertex at current position\ndef isSafe(vertex, adjMat, path, pos):\n\n # The vertex must be adjacent to the previous vertex\n if adjMat[path[pos - 1]][vertex] == 0:\n return False\n\n # The vertex must not already be in the path\n for i in range(pos):\n if path[i...
hamiltonian-cycle.json
9
length-of-longest-common-prime-subsequence-from-two-given-arrays
Length of longest common prime subsequence from two given arrays
Given two arrays arr1[] and arr2[] of length N and M respectively, the task is to find the length of the longest common prime subsequence that can be obtained from the two given arrays.
1
arr1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}, arr2[] = {2, 5, 6, 3, 7, 9, 8}
4 Explanation: The longest common prime subsequence present in both the arrays is {2, 3, 5, 7}.
1
sol1
cpp
// CPP implementation of the above approach\n#include <bits/stdc++.h>\nusing namespace std;\n\n// Function to calculate the LCS\nint recursion(vector<int> arr1,\n vector<int> arr2, int i,\n int j, map<pair<int, int>, \n int> dp)\n{\n if (i >= arr1.size() or j >= arr2.size())\n ...
length-of-longest-common-prime-subsequence-from-two-given-arrays.json
9
length-of-longest-common-prime-subsequence-from-two-given-arrays
Length of longest common prime subsequence from two given arrays
Given two arrays arr1[] and arr2[] of length N and M respectively, the task is to find the length of the longest common prime subsequence that can be obtained from the two given arrays.
1
arr1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}, arr2[] = {2, 5, 6, 3, 7, 9, 8}
4 Explanation: The longest common prime subsequence present in both the arrays is {2, 3, 5, 7}.
2
sol2
java
// JAVA implementation of the above approach\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class InfobayAI\n{\n\n // Function to calculate the LCS\n static int recursion(ArrayList<Integer> arr1,\n ArrayList<Integer> arr2, int i,\n int j, Map<ArrayList...
length-of-longest-common-prime-subsequence-from-two-given-arrays.json
9
length-of-longest-common-prime-subsequence-from-two-given-arrays
Length of longest common prime subsequence from two given arrays
Given two arrays arr1[] and arr2[] of length N and M respectively, the task is to find the length of the longest common prime subsequence that can be obtained from the two given arrays.
1
arr1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}, arr2[] = {2, 5, 6, 3, 7, 9, 8}
4 Explanation: The longest common prime subsequence present in both the arrays is {2, 3, 5, 7}.
3
sol3
python
# Python implementation of the above approach\n\n# Function to calculate the LCS\n\ndef recursion(arr1, arr2, i, j, dp):\n if i >= len(arr1) or j >= len(arr2):\n return 0\n key = (i, j)\n if arr1[i] == arr2[j]:\n return 1 + recursion(arr1, arr2,\n i + 1, j + 1, dp)\n ...
length-of-longest-common-prime-subsequence-from-two-given-arrays.json
9
length-of-longest-common-prime-subsequence-from-two-given-arrays
Length of longest common prime subsequence from two given arrays
Given two arrays arr1[] and arr2[] of length N and M respectively, the task is to find the length of the longest common prime subsequence that can be obtained from the two given arrays.
2
arr1[] = {1, 3, 5, 7, 9}, arr2[] = {2, 4, 6, 8, 10}
0 Explanation: In the above arrays, the prime subsequence of arr1[] is {1, 3, 5, 7} and arr2[] is {2}. Therefore, there is no common prime numbers which are present in both the arrays. Hence, the result is 0.
1
sol1
cpp
// CPP implementation of the above approach\n#include <bits/stdc++.h>\nusing namespace std;\n\n// Function to calculate the LCS\nint recursion(vector<int> arr1,\n vector<int> arr2, int i,\n int j, map<pair<int, int>, \n int> dp)\n{\n if (i >= arr1.size() or j >= arr2.size())\n ...
length-of-longest-common-prime-subsequence-from-two-given-arrays.json
9
length-of-longest-common-prime-subsequence-from-two-given-arrays
Length of longest common prime subsequence from two given arrays
Given two arrays arr1[] and arr2[] of length N and M respectively, the task is to find the length of the longest common prime subsequence that can be obtained from the two given arrays.
2
arr1[] = {1, 3, 5, 7, 9}, arr2[] = {2, 4, 6, 8, 10}
0 Explanation: In the above arrays, the prime subsequence of arr1[] is {1, 3, 5, 7} and arr2[] is {2}. Therefore, there is no common prime numbers which are present in both the arrays. Hence, the result is 0.
2
sol2
java
// JAVA implementation of the above approach\nimport java.util.*;\nimport java.io.*;\nimport java.math.*;\npublic class InfobayAI\n{\n\n // Function to calculate the LCS\n static int recursion(ArrayList<Integer> arr1,\n ArrayList<Integer> arr2, int i,\n int j, Map<ArrayList...
length-of-longest-common-prime-subsequence-from-two-given-arrays.json
9
length-of-longest-common-prime-subsequence-from-two-given-arrays
Length of longest common prime subsequence from two given arrays
Given two arrays arr1[] and arr2[] of length N and M respectively, the task is to find the length of the longest common prime subsequence that can be obtained from the two given arrays.
2
arr1[] = {1, 3, 5, 7, 9}, arr2[] = {2, 4, 6, 8, 10}
0 Explanation: In the above arrays, the prime subsequence of arr1[] is {1, 3, 5, 7} and arr2[] is {2}. Therefore, there is no common prime numbers which are present in both the arrays. Hence, the result is 0.
3
sol3
python
# Python implementation of the above approach\n\n# Function to calculate the LCS\n\ndef recursion(arr1, arr2, i, j, dp):\n if i >= len(arr1) or j >= len(arr2):\n return 0\n key = (i, j)\n if arr1[i] == arr2[j]:\n return 1 + recursion(arr1, arr2,\n i + 1, j + 1, dp)\n ...
length-of-longest-common-prime-subsequence-from-two-given-arrays.json
10
lexicographically-smallest-permutation-of-a-string-that-can-be-reduced-to-length-k-by-removing-k-length-prefixes-from-palindromic-substrings-of-length-2k
Lexicographically smallest permutation of a string that can be reduced to length K by removing K-length prefixes from palindromic substrings of length 2K
Given a binary string str of length N, and an integer K, the task is to find the lexicographically smallest permutation of the string str that can be reduced to length K by removal of every K-length prefix from palindromic substrings of length 2K. If no such permutation exists, print "Not Possible".
1
str = "0000100001100001”, K = 4
0001100000011000 Explanation: In the string "0001100000011000", every 2K length substring becomes a palindrome whenever a K-length prefix is removed, until string length reduces to K.
1
sol1
cpp14
// C++ program for the above approach\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n// Function to count the number of\n// zeroes present in the string\nint count_zeroes(int n, string str)\n{\n int cnt = 0;\n\n // Traverse the string\n for (int i = 0; i < str.size(); i++) {\n if (str[i] == '0')\n...
lexicographically-smallest-permutation-of-a-string-that-can-be-reduced-to-length-k-by-removing-k-length-prefixes-from-palindromic-substrings-of-length-2k.json
10
lexicographically-smallest-permutation-of-a-string-that-can-be-reduced-to-length-k-by-removing-k-length-prefixes-from-palindromic-substrings-of-length-2k
Lexicographically smallest permutation of a string that can be reduced to length K by removing K-length prefixes from palindromic substrings of length 2K
Given a binary string str of length N, and an integer K, the task is to find the lexicographically smallest permutation of the string str that can be reduced to length K by removal of every K-length prefix from palindromic substrings of length 2K. If no such permutation exists, print "Not Possible".
1
str = "0000100001100001”, K = 4
0001100000011000 Explanation: In the string "0001100000011000", every 2K length substring becomes a palindrome whenever a K-length prefix is removed, until string length reduces to K.
2
sol2
java
// Java program for the above approach\nimport java.io.*;\n\nclass InfobayAI{\n\n// Function to count the number of\n// zeroes present in the string\nstatic int count_zeroes(int n, String str)\n{\n int cnt = 0;\n \n // Traverse the string\n for(int i = 0; i < str.length(); i++) \n {\n if (str.char...
lexicographically-smallest-permutation-of-a-string-that-can-be-reduced-to-length-k-by-removing-k-length-prefixes-from-palindromic-substrings-of-length-2k.json
10
lexicographically-smallest-permutation-of-a-string-that-can-be-reduced-to-length-k-by-removing-k-length-prefixes-from-palindromic-substrings-of-length-2k
Lexicographically smallest permutation of a string that can be reduced to length K by removing K-length prefixes from palindromic substrings of length 2K
Given a binary string str of length N, and an integer K, the task is to find the lexicographically smallest permutation of the string str that can be reduced to length K by removal of every K-length prefix from palindromic substrings of length 2K. If no such permutation exists, print "Not Possible".
1
str = "0000100001100001”, K = 4
0001100000011000 Explanation: In the string "0001100000011000", every 2K length substring becomes a palindrome whenever a K-length prefix is removed, until string length reduces to K.
3
sol3
python
# Python3 program for the above approach\n\n# Function to count the number of\n# zeroes present in the string\ndef count_zeroes(n, str):\n \n cnt = 0\n\n # Traverse the string\n for i in range(0, len(str)):\n if (str[i] == '0'):\n cnt += 1\n \n # Return the count\n return cnt\n\n# Function to rearran...
lexicographically-smallest-permutation-of-a-string-that-can-be-reduced-to-length-k-by-removing-k-length-prefixes-from-palindromic-substrings-of-length-2k.json
10
lexicographically-smallest-permutation-of-a-string-that-can-be-reduced-to-length-k-by-removing-k-length-prefixes-from-palindromic-substrings-of-length-2k
Lexicographically smallest permutation of a string that can be reduced to length K by removing K-length prefixes from palindromic substrings of length 2K
Given a binary string str of length N, and an integer K, the task is to find the lexicographically smallest permutation of the string str that can be reduced to length K by removal of every K-length prefix from palindromic substrings of length 2K. If no such permutation exists, print "Not Possible".
2
str = "100111", K = 2
"Not Possible"
1
sol1
cpp14
// C++ program for the above approach\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n// Function to count the number of\n// zeroes present in the string\nint count_zeroes(int n, string str)\n{\n int cnt = 0;\n\n // Traverse the string\n for (int i = 0; i < str.size(); i++) {\n if (str[i] == '0')\n...
lexicographically-smallest-permutation-of-a-string-that-can-be-reduced-to-length-k-by-removing-k-length-prefixes-from-palindromic-substrings-of-length-2k.json
10
lexicographically-smallest-permutation-of-a-string-that-can-be-reduced-to-length-k-by-removing-k-length-prefixes-from-palindromic-substrings-of-length-2k
Lexicographically smallest permutation of a string that can be reduced to length K by removing K-length prefixes from palindromic substrings of length 2K
Given a binary string str of length N, and an integer K, the task is to find the lexicographically smallest permutation of the string str that can be reduced to length K by removal of every K-length prefix from palindromic substrings of length 2K. If no such permutation exists, print "Not Possible".
2
str = "100111", K = 2
"Not Possible"
2
sol2
java
// Java program for the above approach\nimport java.io.*;\n\nclass InfobayAI{\n\n// Function to count the number of\n// zeroes present in the string\nstatic int count_zeroes(int n, String str)\n{\n int cnt = 0;\n \n // Traverse the string\n for(int i = 0; i < str.length(); i++) \n {\n if (str.char...
lexicographically-smallest-permutation-of-a-string-that-can-be-reduced-to-length-k-by-removing-k-length-prefixes-from-palindromic-substrings-of-length-2k.json
10
lexicographically-smallest-permutation-of-a-string-that-can-be-reduced-to-length-k-by-removing-k-length-prefixes-from-palindromic-substrings-of-length-2k
Lexicographically smallest permutation of a string that can be reduced to length K by removing K-length prefixes from palindromic substrings of length 2K
Given a binary string str of length N, and an integer K, the task is to find the lexicographically smallest permutation of the string str that can be reduced to length K by removal of every K-length prefix from palindromic substrings of length 2K. If no such permutation exists, print "Not Possible".
2
str = "100111", K = 2
"Not Possible"
3
sol3
python
# Python3 program for the above approach\n\n# Function to count the number of\n# zeroes present in the string\ndef count_zeroes(n, str):\n \n cnt = 0\n\n # Traverse the string\n for i in range(0, len(str)):\n if (str[i] == '0'):\n cnt += 1\n \n # Return the count\n return cnt\n\n# Function to rearran...
lexicographically-smallest-permutation-of-a-string-that-can-be-reduced-to-length-k-by-removing-k-length-prefixes-from-palindromic-substrings-of-length-2k.json
README.md exists but content is empty.
Downloads last month
35