We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
vector<int>kFactorization(intn,vector<int>A){// sort Asort(A.begin(),A.end());// initialize answer vectorvector<int>ans;// loopinti=A.size()-1;while(n!=1&&i>=0){while(n%A[i]==0){ans.push_back(n);n=n/A[i];}i--;}// if no way to reach N print -1if(n!=1){ans.clear();ans.push_back(-1);returnans;}// else return answerans.push_back(1);reverse(ans.begin(),ans.end());returnans;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
K Factorization
You are viewing a single comment's thread. Return to all comments →
Simple solution