Rabbit Jumping Problem

Consider 'n' carrots numbered from 1 to 'n' and 'k' rabbits. Each rabbit jumps to carrots only at multiples of its respective jumping factor Aj (i.e., Aj, 2Aj, 3Aj, ...), for all rabbits from 1 to k.

When a rabbit reaches a carrot, it eats a little portion of it. All rabbits start from the same starting point. Your task is to determine and return the total count of carrots that remain uneaten after all rabbits have finished jumping.

Input:

The first line contains an integer 'T' indicating the number of test cases.
Each test case comprises two lines.
First line: two integers 'n' and 'k' indicating the number of carrots and rabbits.
Second line: 'k' space-separated integers representing the jumping factors of the rabbits.

Output:

A single integer for each test case indicating the number of carrots that were not eaten.

Example:

Input:
1
10 2
2 3
Output:
3
Explanation:

With 10 carrots and rabbits jumping on multiples of 2 and 3, carrots 2, 3, 4, 6, 8, 9, 10 will be eaten by the rabbits, leaving carrots 1, 5, and 7 uneaten.

Constraints:

  • 1 <= 'T' <= 50
  • 1 <= 'n', 'k' <= 3000
  • 1 <= A[j] <= n, for all j from 1 to k
  • Time Limit: 1 second
AnswerBot
4mo

Calculate uneaten carrots by rabbits with specific jumping factors.

  • Iterate through each carrot and check if any rabbit jumps on it.

  • Use the jumping factors to determine which carrots will be eaten.

  • Subt...read more

Help your peers!
Select
Add answer anonymously...

DE Shaw Software Developer interview questions & answers

A Software Developer was asked 12mo agoQ. Given a binary tree and a target node, burn the tree starting from the target no...read more
A Software Developer was asked Q. What is the purpose of Normalization?
A Software Developer was asked Q. What is the difference between a default constructor and a copy constructor?

Popular interview questions of Software Developer

A Software Developer was asked 12mo agoQ1. Given a binary tree and a target node, burn the tree starting from the target no...read more
A Software Developer was asked Q2. What is the purpose of Normalization?
A Software Developer was asked Q3. What is the difference between a default constructor and a copy constructor?
DE Shaw 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