Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are given N fractions, numbered from 0 to N - 1 . Your task is to count the number of occurrences of the fraction

You are given N fractions, numbered from 0 to N-1. Your task is to count the number of occurrences of the fraction that appears most often. Notice that two fractions may be equal even if they have different representations; for example, 3/5 and 6/10 are equal. You should not assume that floating point operations are precise.
Write a function:
int solution(vector &X, vector &Y);
that, given two arrays X and Y consisting of N integers each (which represent the k-th fraction as X[k]/Y[k]) returns the number of occurrences of the fraction that appears most often.
Examples:
1. Given arrays X =[1,2,3,4], Y =[2,3,6,8], the function should return 3 as fractions 1/2,3/6,4/8 are all equal to each other.
2. Given arrays X =[3,3,4], Y =[5,3,4], the function should return 1, as no two fractions are equal.
3. Given arrays X =[4,7,1,2], Y =[2,14,1,2], the function should return 2, as fractions 1/2 and 2/4 are equal.
4. Given arrays X =[1,2,3,1,2], Y =[2,6,5,1,1], the function should return 2, as fractions 4/4,4/1,1/2,2/2 are all equal to each other.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- each element of array X is an integer within the range [0..2,000,000,000];
- each element of array Y is an integer within the range [1..2,000,000,000];
- arrays X and Y are of equal length.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

P (z Answered: 1 week ago

Answered: 1 week ago

Question

What is a (a) dichotomous variable? (b) binary variable?

Answered: 1 week ago

Question

9.7 List and briefly discuss four management development methods.

Answered: 1 week ago