The best part of this video is when he also says you can watch that video. which makes me easier to relate it with other problems. thanks for your work sir.
you may have to try some tricks because if you see a lower value in future and pop then its wrong (L to R). (R to L) decreasing stack again may not work as highest weight digits may have high value as compared to others. So, I wont use it
Will you please make a video about your dsa course so that it will give clarity whether to join or not as im very intrested but no proper guide is there about your course.
The simplest answer is here, happy to explain if you need help :)) class Solution: def maximumSwap(self, num: int) -> int: num_list = [int(i) for i in str(num)] max_iter = len(num_list) - 1 num_dict = {} for i, x in enumerate(num_list): if x not in num_dict: num_dict[x] = [i] else: num_dict[x].append(i) i = 0 while i < max_iter: tmp_list = num_list[i::] small = min(tmp_list) big = max(tmp_list) if num_list[i] == big: pass else: ith_elm = num_list[i] num_list[i] = big num_list[num_dict[big][-1]] = ith_elm break i += 1 output_num = 0 digit_place = 10**max_iter for i in num_list: output_num += digit_place * i digit_place //= 10 return output_num
The best part of this video is when he also says you can watch that video. which makes me easier to relate it with other problems. thanks for your work sir.
Thanks! Glad you found it helpful.
best YT channel of DSA problem solving
thanks for your appreciation :)
Best solution so far
Thanks :)
Thankyou so much your video are helping me a lot
great 👍🏼
Thank You SirJi :)
welcome :)
you are the goat
😅
time complexity is O(N^2) for first 2 approaches 2 parse and selection sort
can you please elaborate ?
can we use montonic decreasing stack?
you may have to try some tricks because if you see a lower value in future and pop then its wrong (L to R).
(R to L) decreasing stack again may not work as highest weight digits may have high value as compared to others. So, I wont use it
Will you please make a video about your dsa course so that it will give clarity whether to join or not as im very intrested but no proper guide is there about your course.
I will make a private video and share on whatsapp. I hope you have queried us on whatsapp.
@@techdose4u yes sir
The simplest answer is here, happy to explain if you need help :))
class Solution:
def maximumSwap(self, num: int) -> int:
num_list = [int(i) for i in str(num)]
max_iter = len(num_list) - 1
num_dict = {}
for i, x in enumerate(num_list):
if x not in num_dict:
num_dict[x] = [i]
else:
num_dict[x].append(i)
i = 0
while i < max_iter:
tmp_list = num_list[i::]
small = min(tmp_list)
big = max(tmp_list)
if num_list[i] == big:
pass
else:
ith_elm = num_list[i]
num_list[i] = big
num_list[num_dict[big][-1]] = ith_elm
break
i += 1
output_num = 0
digit_place = 10**max_iter
for i in num_list:
output_num += digit_place * i
digit_place //= 10
return output_num
nice
I am not able to do any questions or projects. I understand everything when I watch the tutorial. I feel I am stuck in tutorial hell. Please help me
TH-cam videos are only for you to solve one particular problem but cant help you with everything.
You can ping us on whatsapp to assist you.
Your 2nd Method fails on test case for num=1993 🤡
I think you can make the changes taking selection technique into consideration and playing with equality :)
@@techdose4u if i would play with equality then another case num=98368 will fail 🤷
Mine got accepted. You might be doing something wrong. Code for your reference :
class Solution {
public:
int maximumSwap(int num) {
string s = to_string(num);
int n = s.size();
vector rightMax(n);
rightMax[n-1] = n-1;
for(int i=n-2; i>=0; i--) {
if(s[i] > s[rightMax[i+1]])
rightMax[i] = i;
else
rightMax[i] = rightMax[i+1];
}
for(int i=0; i
@@techdose4u yeah u r right,ur 2nd method also worked.....
int maximumSwap(int num) {
vectorno;
int t=num;
while(t!=0){
no.push_back(t%10);
t=t/10;
}
reverse(no.begin(),no.end());
vectorind(no.size());
int n=no.size();
int maxi=INT_MIN;
int max_ind=n-1;
for(int i=n-1;i>=0;i--){
if(no[i]>maxi){
ind[i]=i;
max_ind=i;
maxi=no[i];
}
else if(no[i]