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.
Be the first one to answer
Select
Add answer anonymously...

Top Software Developer Interview Questions Asked at Cadence Design Systems

Q. Given an array, reverse the order of its elements in place.
Q. How would you find the sum of two numbers in a linear array (both sorted and uns...read more
Q. Given the coordinates of a point and a rectangle, how would you determine if the...read more
Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits