I was trying to solve this question.
I tried to come up with the following approach.
First sort all the numbers then iterate from large to small while doing these steps, Suppose the number we are currently iterating is num.
Find how many factors of the number num are there in the array.
Suppose it is x, then we have Select at least one factor of num total ways to have the number num as the maximum, also we have the remaining (n-x) numbers, which can give Left numbers other choices.
We multiply these two and get the total ways we will get the number num as our answer. So, for each number a[i](from max to min), we have Final Answer for each array element as contribution to answer.
But I am getting wrong answer in Sample Test Case 3 this way. I think I am overcounting somewhere. Here is, my code.
Where am I overcounting?
I will be thankful for any help!
CandidFlakes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.