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.
- Prepare
- Algorithms
- Greedy
- Accessory Collection
- Discussions
Accessory Collection
Accessory Collection
+ 0 comments Here is my solution in java, javascript, python, C, C++, Csharp HackerRank Accessory Collection Problem Solution
+ 0 comments can anyone find my mistake ? I think it is quite simple.
string acessoryCollection(int L, int A, int N, int D) { long long ans=0; if(N<D) ans=-1; else if(D==1){ ans=L*A; } else{ int min=N-D+1; while(L>min){ if(A==0) { ans=-1; break; } ans+=min*A; A--; L-=min; } if(L>0 & A==0) ans=-1; else if(L>0) ans+=L*A; } //cout << ans<<endl; string str; while(ans>0){ str.push_back('0'+ans%10); ans=ans/10; } if(str.size()!=0){ reverse(str.begin(),str.end()); } if(ans==-1) return "SAD"; else return str; }
+ 0 comments Here is the solution of Accessory Collection Click Here
+ 0 comments Here is problem solution - https://programs.programmingoneonone.com/2021/07/hackerrank-accessory-collection-problem-solution.html
+ 0 comments is this question a greedy algorithm question
Load more conversations
Sort 21 Discussions, By:
Please Login in order to post a comment