Rabbit Jumping

You are given ‘n’ carrots numbered from 1 to ‘n’. There are k rabbits. Rabbits can jump to carrots only with the multiples of Aj(Aj,2Aj,3Aj…) for all rabbits from 1 to k.

Whenever Rabbit reaches a carrot it eats a little carrot. All rabbits start from the same beginning point. You have to determine the remaining carrots(i.e., carrots which are not eaten by any rabbit) after all rabbits reach the end.

Input Format:
The first line of input contains an integer 'T' denoting the number of test cases.

The first line of the test case contains 'n' and 'k' denoting the number of carrots and rabbits.

The next line contains 'k' space-separated integers denoting the jumping factor of the rabbits.
Output Format:
Return a single integer representing the number of remaining carrots.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= 'T' <= 50
1 <= 'n', 'k' <= 3000
1 <= A[ j ] <= n, for all j from 1 to k

Time Limit: 1 second
CodingNinjas
author
2y

Tip 1 : Prepare Subjects in Depth for Technical Coding & Interview Round. Cracking the DE Shaw interview is not possible just by reading the short articles one night before.They ask the questions in-d...read more

CodingNinjas
author
2y
Brute Force Approach

Explanation:

The main idea is to traverse all multiples of A[j] for all j from 1 to k. After traversing the total number of left carrots will be the answer.

Algorithm :

  • Create a b...read more
CodingNinjas
author
2y
Optimized Approach

Explanation:

The main idea is to traverse all multiples of A[j] for all j from 1 to k. If a particular A[j] have been traversed then we don’t need to traverse its multiples(When A[j...read more

Add answer anonymously...
DE Shaw Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter