Longest Common Prime Subsequence Problem Statement
Imagine Ninja is tackling a puzzle during his long summer vacation. He has two arrays of integers, each with lengths 'N' and 'M'. Ninja's task is to determine the length of the longest subsequence that is common to both arrays and consists only of prime numbers.
Example:
Input:
T = 1
N = 4, M = 5
arr1 = [2, 3, 4, 5]
arr2 = [3, 5, 7, 11, 13]
Output:
2
Explanation:
The prime numbers that are common to both arrays are 3 and 5. Hence, the length of the longest common prime subsequence is 2.
Constraints:
- 1 <= T <= 5
- 1 <= N, M <= 5 * 102
- 1 <= arr1[i], arr2[i] <= 300
- Time Limit: 1 sec.
Note:
- A subsequence is a sequence that can be derived from another sequence by zero or more elements, without changing the order of the remaining elements.
- You don't need to print anything, the printing has already been taken care of. Just implement the given function.

AnswerBot
4mo
Find the length of the longest subsequence common to two arrays consisting only of prime numbers.
Iterate through both arrays to find prime numbers
Use dynamic programming to find the longest common sub...read more
Help your peers!
Add answer anonymously...
Cadence Design Systems Software Developer interview questions & answers
A Software Developer was asked 6mo agoQ. Given an array, reverse the order of its elements in place.
A Software Developer was asked Q. Given the coordinates of a point and a rectangle, how would you determine if the...read more
A Software Developer was asked Q. You are given an array of elements. Some or all of them are duplicates. Find the...read more
Popular interview questions of Software Developer
A Software Developer was asked 6mo agoQ1. Given an array, reverse the order of its elements in place.
A Software Developer was asked Q2. Given the coordinates of a point and a rectangle, how would you determine if the...read more
A Software Developer was asked Q3. You are given an array of elements. Some or all of them are duplicates. Find the...read more
>
Cadence Design Systems Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

