Комментарии:
Sir what to do when right approach does not hit in my brain i always use the tags and hints to solve the problems and sometimes i am not able to solve the problem after looking at tags and hints both :(
ОтветитьHope your dad feels better soon, sir. Wishing him good health and comfort. ❤❤
ОтветитьTakecare of your dad sir❤
ОтветитьThank you for this!
I hope your dad gets well soon!🌸
I hope your dad gets well soon
Solved it by my own.... Here for your explanation 🫡
class Solution {
public:
int n;
void checkLex(string &word,char &lex,int i,int &idx){
int x=idx,y=i;
while(x<n && y<n){
if(word[x+1]!=word[y+1]){
idx=(word[x+1]<word[y+1])?i:idx;
break;
}
x++,y++;
}
}
string answerString(string word, int numFriends) {
n=word.length();
if(numFriends==1) return word;
char lex=word[0];
int idx=0;
for(int i=0;i<n;i++){
if(lex==word[i]){
checkLex(word,lex,i,idx);
}
else if(lex<word[i]){
lex=word[i];
idx=i;
}
}
int x=n-numFriends+1;
return word.substr(idx,x);
}
};
Take care of your Dad Sir
ОтветитьI have no idea how you manage your time. You are an inspiration.
I pray your dad recovers soon. take care
I hope you're dad well soon🎉❤
ОтветитьPitaji ke liye prarthna bhai .
Ответитьit should be n-i+1 , not n-i
ОтветитьMay Your Father Get well soon 💮
ОтветитьEven in tough times, your dedication is inspiring — prayers for your father’s health and thank you for always showing up for us 🙏❤
ОтветитьTake care of your Dad Sir
Ответить❤
ОтветитьPraying for the wellness of your Father, MIK Sir….
ОтветитьHope your dad get well soon ❣
ОтветитьMay your Father get well soon ❤❤
ОтветитьWishing him a speedy recovery.
ОтветитьMay your father gets well soon
ОтветитьWishing your father a speedy recovery
Ответитьpraying for speedy recovery of your father
ОтветитьAmazing, you are awesome, Thank you very much!
Hope your dad gets well soon!
My wishes to your father for a speedy recovery.
ОтветитьSolved it on my own after u said the intuition of size() - friends + 1:
class Solution {
public:
string answerString(string word, int numFriends) {
int n = word.size();
//I can give max (word.size()-numfriends+1) to 1 frnd such tht others get 1 char each
char x = *max_element(word.begin(),word.end());
vector<int> indices;
for(int i = 0; i< n; i++){
if(word[i] == x){
indices.push_back(i);
}
}
if(numFriends == 1){
return word;
}
vector<string> s;
int temp = word.size() - numFriends + 1;
for (int idx : indices) {
int len = min(temp, (int)word.size() - idx);
string sub = word.substr(idx, len);
s.push_back(sub);
}
string res = s[0];
for(int i = 1; i< s.size(); i++){
if(s[i].compare(res) > 0){
res = s[i];
}
}
return res;
}
};
This is how i did it in O(n*n)
Noted down the indices of the largest char in the string
Take the substring from i-n if remaining friends length is less than i
if there are more friends remaining than i, calculate how many remaining and remove that from the end
then take the substr from i
Lets say there are 5 friends , words length is 12, we have found a largest char at index 3, it means index 0,1,2 can be given to other people, but there are total 5 friends so 1 more person is left who will get the last char in word at index 11, so from index [3,10] we have the lexicographically largest word
in this cas eif the total friends were less than index then we take the whole substr from [index,n-1], we repeat this for all indices at which we found the largest char
may your father get well soon
ОтветитьHope your dad get well soon
ОтветитьPrayers for our Uncle. Wishing him speedy recovery.
Ответитьmay god make your father healthy and happy again
Ответитьplease explain the linear solution also
ОтветитьGet well soon uncle ji 🙏🙏
Ответитьmay your father gets well soon brother. I pray to god for your family's good health
ОтветитьI hope you're father is well.
ОтветитьWishing the fast recovery for uncle!!
Stay strong and keep giving us an update on his health <3
Sending positive energies for your father's speedy recovery.
ОтветитьMay Your Father Get well soon
radhe-radhe❤
Nice one MIK ❤️
ОтветитьWishing a speedy recovery for your father 🙏🙏
ОтветитьUncle will get well soon ❤🙏
Ответитьwishing fast recovery for uncle😇❤
Ответитьwishing fast recovery for your dad , mate
ОтветитьMay your dad get well soon sir
Ответитьwhy my code is stuck on test case 702 word =
"nbjnc"
numFriends =
2
Use Testcase
Output
"nbjn"
Expected
"nc" =>
class Solution {
public String answerString(String word, int numFriends) {
int n=word.length();
if(numFriends<=1) return word;
int largestCharIdx=0;
int curr=word.charAt(0);
for(int i=1;i<n;i++){
int c=word.charAt(i);
if(c > curr){
largestCharIdx=i;
curr=c;
}
}
int end=Math.min(n, largestCharIdx+(n-numFriends+1));
return word.substring(largestCharIdx,end);
}
}
inshallah he will get well soon
ОтветитьWishing fast recovery for your dad , sir!
ОтветитьHats off to you
Ответитьwishing fast recovery for your dad , sir
Ответитьhow is your father now mike?
Ответить