POTD- 15/07/2024 | Smallest Number | Problem of the Day | GeeksforGeeks Practice
Вставка
- Опубліковано 27 сер 2024
- Welcome to the daily solving of our PROBLEM OF THE DAY with Jay Dalsaniya. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Data Structures and Algorithms but will also help you build up problem-solving skills.
So come along and solve the GFG POTD of 15thJuly 2024 with us!
💻 Try it Yourself: practice.geeks...
Find daily solutions for POTD here on our channel! Make sure you are subscribed and stay updated.
-----------------------------------------------------------------------------------------
🏆 Take part in our Weekly Coding Contests: practice.geeks...
📖 Master Competitive Programming - Complete Beginner to Advanced: practice.geeks...
-----------------------------------------------------------------------------------------
Follow us and stay updated on everything happening in the world of geeks:
📱 Twitter- / geeksforgeeks
📝 LinkedIn- / geeksforgeeks
🌐 Facebook- / geeksforgeeks.org
📷 Instagram- www.instagram....
#GFGPractice #GeeksforGeeks #ProblemofTheDay #CodingQuestions #POTD #POTD15JULY #problemsolving #practice #dsa #smallestnumber #greedy #datastructures #alogrithim #jaydalsaniya #gfgpractice
nice explanation
Best explanation
My soln ---> same approach but a little easy to implement
string smallestNumber(int s, int d) {
// code here
if(d*9
My solution:
string smallestNumber(int s, int d) {
if(s > 9*d) return "-1";
int max = 9*(d-1);
string ans;
for(int i=0;i max){
ans.push_back(c);
s -= rem;
}
else {
if(i==0)
{
ans.push_back('1');
s--;
}
else {
ans.push_back('0');
}
}
max-=9;
}
return ans;
}