But in that case how will you justify for arr = [1, 9, 17]
2 MCQs + 3 Coding questions , 2hours time MCQ Q1 : Given graph , find number of edges that are bridge. Q2 : Clean code principles
We are given an array containing integers. We have to convert this array such that the resulting array is a geometric progression. What we need to return is the multiplying ratio of this geometric progression. We have to make sure we make a resulting array such that ratio is maximum.
Example
Given array = [64 , 100 , 125]
Resulting array = [64 , 80 , 100 , 125]
Answer : ratio in simplest form = 5/4
contraints : Array size <= 1e5
Equation : (a*m)%n = r Given a , n , r : Find smallest m such that the above equation satisfies.
constraints : a,n,r <= 1e18
Given a list of strings. and a 2d matrix containing different letters.
We have to choose letters from the matrix to create the list of string with the condition that if you choose some letter from ith row , that row gets erased. (Basically , you can choose only one letter per row)
return if its possible or not to create all words.
Example :
words = ["sony"]
matrix:
s s s s
s n n n
n s o s
y o s y
answer = true , cells = [(0,0) , (2,2) , (1,1) , (3,1)]
constraints : list size <= 1e5 , matrix columns = 6 , matrix rows <= 15
We can reduce this problem to the classical Maximum Bipartite Matching problem.
Question 1 : Approach ( All tests passed )
-> For each element in the array , prime factorize it (store it like a map)
-> The max ratio that needs to be printed would be surely gcd of the powers of individual primes for each array integer. (think !)
-> Some primes will increase from left to right , while some will decrease from left to right.
-> this will be useful for understanding which primes would be part of numerator / denominator.
-> Eg=> [64 , 100 , 125] -> [ {2:6 , 5:0} , {2:2 , 5:2} , {2:0 , 5:3} ]
-> increasing prime = 5 (will come in numerator)
-> decreasing prime = 2 (will come in denominator)
-> our ratio will be (5^a)/(2^b)
-> a = gcd(0,2,3) = 1
-> b = gcd(6,2,0) = 2
-> answer = (5^1) / (2^2) == 5/4
-> If there is some prime which is not monotonic, then return -1. (However , they gave only valid arrays as tests)
complexity = O(Nlogn) (for sieve) , however O(Nsqrt(N)) was also accepted.
Question 2
Prerequisite: Linear Congruence Equation
> Step By Step Solution :
> There can be Multiple cases for the solution
Question 3
Understanding Problem
Approach (For smaller constraints where N amd M are less than 5)
Question 1
Breakdown
Approach
Gigaliths In question 1, were there any other constraints? Like, Is it necessary for array elements to be integer, etc?
As of now we are only have this details only . If we get more information we will update it ..yes array elements are integers only as it is written on first line : -) Keep grinding 🙂
What if we are not able to convert it to a geometric progression @Akshay Sharma-2766 , should we return -1 or something else ? like in the case of [1, 9, 17]
Given input array is integer. But resulting array need not be an integer array.