TCS Logo

Asked in TCS

Prime Time Again Problem Statement

You are given two integers DAY_HOURS and PARTS. The integer 'DAY_HOURS' represents the number of hours in a day, and the day can be divided into 'PARTS' equal parts. Your task is to determine the total instances of equivalent prime groups. A prime group refers to a pair of hours that are both prime and measure the same equivalent time from the start of the day, but each hour is in a different part of the day.

Example:

Input:
DAY_HOURS = 20, PARTS = 2
Output:
2
Explanation:

The day can be represented in parts as follows:

1  2  3  4  5  6  7  8  9 10  - Part 1
11 12 13 14 15 16 17 18 19 20 - Part 2

The prime groups are (3, 13) and (7, 17), as both elements in each pair are prime numbers.

Constraints:

  • 1 ≤ T ≤ 100
  • 10 ≤ DAY_HOURS ≤ 5 * 103
  • 2 ≤ PARTS ≤ 103
  • The day should be evenly divided by parts (i.e., DAY_HOURS % PARTS == 0).
  • Time Limit: 1 second
Note:
1. The day starts at hour 1 and ends at hour 'DAY_HOURS'.
2. Each hour of the prime group must be from different parts of the day.
3. If there are no equivalent prime groups, return zero.
4. The number of hours per part must be a natural number.
AnswerBot
4mo

Find total instances of equivalent prime groups in a day divided into equal parts.

  • Iterate through each part of the day and check for prime pairs in different parts

  • Use a helper function to check if a n...read more

Help your peers!
Select
Add answer anonymously...
SDE-2 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